0

I'm going to train my model with 4 classes with images.

Here's my pre-trained code look like

conv_base = EfficientNetB0(weights="imagenet", include_top=False,
                                               input_shape=(224, 224, 3))

I trained my mode with code like this:

eff_history = model.fit(
                        train_generator,
                        validation_data=validation_generator,
                        steps_per_epoch=486 // 20,
                        epochs=10)

But there's problem occured like below:

error

Any help guys?

Kaveh
  • 4,618
  • 2
  • 20
  • 33
  • Post your whole model code. – Abhishek Prajapat Aug 09 '21 at 18:41
  • here's my code bro, https://colab.research.google.com/drive/18AtIP7aOycHPDR84PuQ7iS8aYUdclZIe?usp=sharing thanks for checking – Muhammad Rifqi Aug 10 '21 at 05:11
  • Change this `model.add(layers.Dense(2, activation="softmax", name="fc_out"))` to `model.add(layers.Dense(3, activation="softmax", name="fc_out"))`. The difference is that you have 3 classes in output but you were passing 2 classes from model and hence there was a shape mismatch. – Abhishek Prajapat Aug 10 '21 at 05:21
  • hi man, my code work for 4 class. Thanks for your help. for further communication, may i have your email? to discuss more about this – Muhammad Rifqi Aug 10 '21 at 08:57

1 Answers1

1

You have three labels for each sample, but the last layer of your model outputs 2 classes thus the number of the logits you get is 2 rather than 3. You need to change your model to have a 3 dimensional output.

D. ACAR
  • 290
  • 1
  • 9
  • is there any clue where i should change the code? – Muhammad Rifqi Aug 09 '21 at 14:10
  • Can you provide more information about what you are using and whose or which implementation it is. So I can check out the source and give you better directions. – D. ACAR Aug 09 '21 at 14:40
  • here's my code bro, https://colab.research.google.com/drive/18AtIP7aOycHPDR84PuQ7iS8aYUdclZIe?usp=sharing thanks for checking – Muhammad Rifqi Aug 10 '21 at 05:11
  • Hi can you copy the code I provided above where you define conv_base. I can not run the code at the moment. – D. ACAR Aug 10 '21 at 06:18
  • @D.ACAR that won't be the answer to his question as your edit will make it the whole model and not the `base_model`. Also, in his code, he wants to use `Dropout` which he couldn't use otherwise. I have put the answer in the comment of the question. – Abhishek Prajapat Aug 10 '21 at 06:49
  • Oh I see I did not notice he added some custom layers. – D. ACAR Aug 10 '21 at 07:48