I am using the example here
to classify images. I have 2147 images belonging to 11 classes. I am running the classifier on the batch of images. So far program is going well but I am not able to assign the labels because I am getting the following error on the code: labels_batch=image_labels[np.argmax(result_batch, axis=-1)]
Traceback (most recent call last): > > labels_batch=image_labels[np.argmax(result_batch, axis=-1)] IndexError: index 917 is out of bounds for axis 0 with size 11
More information:
My labels are categories = ["Categorical_Boxplot", "Column_Charts", "Dendogram", "Heatmap", "Line_Chart", "Map","Node-Link_Diagram", "Ordination_Scatterplot", "Pie_Chart", "Scatterplot", "Stacked_Area_Chart"]
and here is how I am trying to assign this label to the classifier
image_labels = np.array(categories)
result_batch = classifier_model.predict(image_batch)
labels_batch = image_labels[np.argmax(result_batch, axis=-1)]
labels_batch
result_batch.shape
(32, 1001)
The shape of my data
Image batch shape: (32, 224, 224, 3) Label batch shape: (32, 11)
I don't know where I am going wrong and how can I fix it? I already tried to append the image_labels to labels_batch instead of assigning it with =
. But it did not work.
Classifier:
classifier_url = "https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/classification/2" #@param {type:"string"}
IMAGE_SIZE = hub.get_expected_image_size(hub.Module(classifier_url))
classifier_layer = layers.Lambda(classifier, input_shape=IMAGE_SIZE + [3])
classifier_model = tf.keras.Sequential([classifier_layer])
classifier_model.summary()