从预先训练的模型Keras获取课程

时间:2019-05-13 07:16:12

标签: python tensorflow keras

我已经训练过模型,现在想从该模型中标记图像数据集

    feature_extractor_url = "https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/2" #@param {type:"string"}
    Categories = ["Categorical_Boxplot", "Column_Charts", "Dendogram", "Heatmap", "Line_Chart", "Map", "Node-Link_Diagram", "Ordination_Scatterplot", "Pie_Chart", "Scatterplot", "Stacked_Area_Chart"]
    image_generator = tf.keras.preprocessing.image.ImageDataGenerator(rescale=1/255)
    IMAGE_SIZE = hub.get_expected_image_size(hub.Module(feature_extractor_url))
    image_data = image_generator.flow_from_directory(str("C:/Users/admin/Desktop/phd python projects/tensorflow_img_class/src/testimg/"),  target_size=IMAGE_SIZE)
    for image_batch,label_batch in image_data:
      print("Image batch shape: ", image_batch.shape)
      print("Label batch shape: ", label_batch.shape)
      break        
  

图像批处理形状:(9,224,224,3),   标签批次形状:(9,1)

    with tf.compat.v1.Session() as sess:
        sess.run(tf.compat.v1.global_variables_initializer())
        export_path ="./test20/{}"
        model_prime = tf.keras.experimental.load_from_saved_model(export_path)
        pred=model_prime(image_batch)
        print(pred.shape)
  

(9,11)

        label_path=np.array(Categories)
        print(label_path)
        predicted_classes = label_path[np.argmax(pred, axis=-1)]
        print(predicted_classes)
  

Categorical_Boxplot

问题就在这里。它只能为我提供1张图像的预测,而不是全部,而从我的模型形状可以看出,我有11个类和9张图像。我不知道这是怎么回事。我的目标是将这个经过预训练的模型应用于90k张图像并预测其标签(在这11张图像中)。这只是对9张图像的小测试。任何帮助将不胜感激

0 个答案:

没有答案
相关问题