Finetune.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:tensorflow-AlexNet 作者: qiansi 项目源码 文件源码
def test_image(path_image,num_class,path_classes,weights_path = 'Default'):
    #x = tf.placeholder(tf.float32, [1,227,227,3])
    x = cv2.imread(path_image)
    x = cv2.resize(x,(227,227))
    x = x.astype(np.float32)

    x = np.reshape(x,[1,227,227,3])
    y = tf.placeholder(tf.float32,[None,num_class])
    model = AlexNet(x,0.5,1000,skip_layer = '', weights_path = weights_path)
    score = model.fc8
    max = tf.arg_max(score,1)
    with tf.Session() as sess:
        sess.run(tf.global_variables_initializer())
        model.load_weights(sess)
        #score = model.fc8
        label_id = sess.run(max)[0]

        with open(path_classes) as f:
            lines = f.readlines()
            label = lines[label_id]
            print('image name is {} class_id is {} class_name is {}'.format(path_image,label_id,label))
            cv2.imshow(label,cv2.imread(path_image))
            cv2.waitKey(0)
        f.close()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号