I have already trained my model and now want to label my image dataset from this model

    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        

Image batch shape: (9, 224, 224, 3), Label batch shape: (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

And the problem lies here. It only gives me prediction on 1 image and not all whereas, as one can see from shape of my model, I have 11 classes and 9 images. I do not know what is wrong with it. My goal is to run this pretrained model to the batch of 90k images and predict its label (out of those 11). And this is just a small test on 9 images. Any help will be appreciated

0 Answers