Issue
I have my own dataset containing 2000 images that I'd like to label. At first, I created numpy array containing labels (0 or 1). For example, for image[0] the corresponding label would be label[0]. Please note that I'm not sure if this is the correct way for labeling.
model= VGG16(include_top=False, input_shape= (32,32,3))
model.summary()
model.compile(optimizer="Adam", loss="binary_crossentropy" , metrics=['accuracy'])
epochs = 10
history = model.fit(x=training_ds, y=training_lb , epochs=epochs, validation_data= (testing_ds, testing_lb) )
training_ds contain all images in shape (n,32,32,3) training_lb contain labels in shape (n,1)
and same for testing.
After running the code I got error, loss is very high and its not learning anything. Is my labeling wrong?
Output:
Solution
I think you are getting 0 accuracy because your model don't have output Dense layer. Use it like this:
import tensorflow as tf
base_model= VGG16(include_top=False, input_shape= (32,32,3))
model = tf.keras.models.Sequential()
model.add(base_model)
model.add(tf.keras.layers.Flatten())
model.add(tf.keras.layers.Dropout(0.2))
model.add(tf.keras.layers.Dense(1, activation='sigmoid'))
And I don't think there is anything wrong with your labelling. But it is very time-consuming. Instead, you could have just made two different folders and rename those folders as labels, i.e. 1 and 0. And then add those images in specific folder. Then use TensorFlow's ImageDataGenerator
to load them.
Answered By - Adarsh Wase
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.