google-coral / tutorials

Colab/Jupyter tutorials about training TensorFlow models for Edge TPU, and other tutorials
Apache License 2.0
181 stars 39 forks source link

Retrain a classification model for Edge TPU using post-training quantization (with TF2) #18

Closed visualturbo closed 2 years ago

visualturbo commented 2 years ago

Hi,

Retreained the model on flower dataset working greate when i train my custom dataset 4200 jpg resized to 224x224px. Tested another size but this is the error always in my dataset on Google Colab.

IMAGE_SIZE = 224 BATCH_SIZE = 64

datagen = tf.keras.preprocessing.image.ImageDataGenerator( rescale=1./255, validation_split=0.2)

train_generator = datagen.flow_from_directory( flowers_dir, target_size=(IMAGE_SIZE, IMAGE_SIZE), batch_size=BATCH_SIZE, subset='training')

val_generator = datagen.flow_from_directory( flowers_dir, target_size=(IMAGE_SIZE, IMAGE_SIZE), batch_size=BATCH_SIZE, subset='validation')

Whats wrong? Can help me?

Epoch 1/10

InvalidArgumentError Traceback (most recent call last)

in () 3 epochs=10, 4 validation_data=val_generator, ----> 5 validation_steps=len(val_generator)) 1 frames /usr/local/lib/python3.7/dist-packages/tensorflow/python/eager/execute.py in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name) 57 ctx.ensure_initialized() 58 tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name, ---> 59 inputs, attrs, num_outputs) 60 except core._NotOkStatusException as e: 61 if name is not None: InvalidArgumentError: logits and labels must be broadcastable: logits_size=[32,5] labels_size=[32,4] [[node categorical_crossentropy/softmax_cross_entropy_with_logits (defined at /usr/local/lib/python3.7/dist-packages/keras/backend.py:5010) ]] [Op:__inference_train_function_25441] Errors may have originated from an input operation. Input Source operations connected to node categorical_crossentropy/softmax_cross_entropy_with_logits: In[0] categorical_crossentropy/softmax_cross_entropy_with_logits/Reshape: In[1] categorical_crossentropy/softmax_cross_entropy_with_logits/Reshape_1:
hjonnala commented 2 years ago

@visualturbo logits_size=[32,5] labels_size=[32,4] seems to be you have 5 classes in datasets but only 4 classes in labels file.

Can you please share colab or data set to reproduce the issue. Thanks!

visualturbo commented 2 years ago

@hjonnala

Many thanks :) Yes i'm use only 4 label and find the problem change units number to 4.

model = tf.keras.Sequential([ base_model, tf.keras.layers.Conv2D(filters=32, kernel_size=3, activation='relu'), tf.keras.layers.Dropout(0.2), tf.keras.layers.GlobalAveragePooling2D(), tf.keras.layers.Dense(units=4, activation='softmax') ])

Thanks Your help. Regards

google-coral-bot[bot] commented 2 years ago

Are you satisfied with the resolution of your issue? Yes No