Example #1
0
parser.add_argument('--max_steps', default=10000, type=int)
parser.add_argument('--snapshot',
                    default=2000,
                    type=int,
                    help='the frequency of saving the latest model')
args = parser.parse_args()

os.environ["CUDA_VISIBLE_DEVICES"] = args.gpu_id

batch_size = data_loader.batch
resize_height = data_loader.IMG_HEIGHT
resize_width = data_loader.IMG_WIDTH
depths = data_loader.IMG_CHANNELS
data_shape = [batch_size, resize_height, resize_width, depths]

_, _, labels_nums = create_csv_files.get_number_of_classification(
    args.dataset_path + 'train/')
print(labels_nums)

# 定义input_images为图片数据
input_images = tf.placeholder(
    dtype=tf.float32,
    shape=[None, resize_height, resize_width, depths],
    name='input')
# 定义input_labels为labels数据
# input_labels = tf.placeholder(dtype=tf.int32, shape=[None], name='label')
input_labels = tf.placeholder(dtype=tf.int32,
                              shape=[None, labels_nums],
                              name='label')

# 定义dropout的概率
keep_prob = tf.placeholder(tf.float32, name='keep_prob')
Example #2
0
    saver = tf.train.Saver()
    saver.restore(sess, models_path)
    images_list=glob.glob(os.path.join(image_dir,'*.jpg'))
    for image_path in images_list:
        im=read_image(image_path,resize_height,resize_width,normalization=True)
        im=im[np.newaxis,:]
        #pred = sess.run(f_cls, feed_dict={x:im, keep_prob:1.0})
        pre_score,pre_label = sess.run([score,class_id], feed_dict={input_images:im})
        max_score=pre_score[0,pre_label]
        print("{} is: pre labels:{},name:{} score: {}".format(image_path,pre_label,list(labels_filename.keys())[list(labels_filename.values()).index(pre_label)], max_score))
    sess.close()


if __name__ == '__main__':

    dataset_path = './dataset/'
    #num of class
    _, dirnames, class_nums = create_csv_files.get_number_of_classification(dataset_path + 'train/')
    labels_filename = create_csv_files.get_classification_label(dirnames, class_nums)

    image_dir='./test_image'
    # labels_filename='dataset/label.txt'
    models_path='models_inception_v1/model.ckpt-10000'

    batch_size = 1  #
    resize_height = 224  # 指定存储图片高度
    resize_width = 224  # 指定存储图片宽度
    depths=3
    data_format=[batch_size,resize_height,resize_width,depths]
    predict(models_path,image_dir, labels_filename, class_nums, data_format)