Answers.Body: <h2>Your model is completely underfit</h2>
  <p><strong>Reasons:</strong></p>
  <ol>
  <li>You have a very small neural network that can't generalize your problem.</li>
  <li>you mentioned 17 classes but in the last layers, you are specifying 16 class <code>layers. Dense(16,activation='softmax')</code> try to fix this.</li>
  <li>If there is a class imbalance you have to remove this which may make your results worst.</li>
  <li>Add more <code>epochs</code> after adding more layers or use pre-trained models.</li>
  </ol>
  <p><strong>Try this code and models:</strong></p>
  <pre><code>base_model = ResNet50V2(weights='imagenet', include_top=False, input_shape=(512,512,3))
   
  for layer in base_model.layers:
      layer.trainable = False
  x = GlobalAveragePooling2D()(base_model.output)
  
  prediction = Dense(17, activation='softmax')(x)
  model = Model(inputs=base_model.input, outputs=prediction)
  model.compile(optimizer = 'adam' , loss='categorical_crossentropy', metrics = ['accuracy'])
  model.summary()
  history = model.fit(x_train,y_train,validation_data=(x_test,y_test),batch_size=32,epochs=10)
  </code></pre>
  <p><strong>Evaulate Model:</strong></p>
  <pre><code>print(history.history.keys())
  #  &quot;Accuracy&quot;
  plt.plot(history.history['accuracy'])
  plt.plot(history.history['val_accuracy'])
  plt.title('model accuracy')
  plt.ylabel('accuracy')
  plt.xlabel('epoch')
  plt.legend(['train', 'validation'], loc='upper left')
  plt.show()
  # &quot;Loss&quot;
  plt.plot(history.history['loss'])
  plt.plot(history.history['val_loss'])
  plt.title('model loss')
  plt.ylabel('loss')
  plt.xlabel('epoch')
  plt.legend(['train', 'validation'], loc='upper left')
  plt.show()
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-03T17:34:56.927Z
Answers.Text: Hard to say without seeing the data, but the model has already 0.9 million trainable parameters so isn't super simple either. But it has very few layers and no convolutions at all, which doesn't seem ideal. But I agree with all of your other points.
Answers.UserDisplayName: NikoNyrh
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-18T05:12:50.403Z
Answers.Text: share your code I will let them with better accuracy
Answers.UserDisplayName: Engr Ali
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-03T11:35:47.873Z
Answers.LastActivityDate: 2022-02-03T11:35:47.873Z
Answers.UserDisplayName: Engr Ali
Body: <p>I'm trying to classify images in <a href="https://www.robots.ox.ac.uk/%7Evgg/data/flowers/17/" rel="nofollow noreferrer">17 flowers</a> dataset which consist of 1360 images of 17 classes (80 images per class); I have to use DNNs only therefore I made my model with the following settings:</p>
  <pre><code>images_net = models.Sequential([layers.Dense(300,input_dim = 3072, activation='relu'),
                                      layers.Dense(30,activation='relu'),
                                      layers.Dense(17,activation='softmax')]);
  
  images_net.compile(optimizer='SGD', loss='categorical_crossentropy',metrics=['accuracy']);
  
  my_net = images_net.fit(x_train,y_train,validation_data=(x_test,y_test),batch_size=32,epochs=10)
  
  </code></pre>
  <p>finally, when I evaluate my model I get the following result:</p>
  <p><a href="https://i.sstatic.net/pFzSC.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/pFzSC.png" alt="co" /></a></p>
  <p>Can anyone explain the result and what the problem is with these settings?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-02-03T11:20:22.060Z
Comments.Text: Hard to help you without more information. What images are you trying to classify, what are the stats of the dataset your using (e.g. size), do you have an expectation about the final performance of the model, i.e. are you trying to replicate some results or just trying your luck? Also loss and metrics are easier to understand when plotted in separate graphs. For now the only striking thing is that you're using a dense neural net rather than a CNN, any reason for that?
Comments.UserDisplayName: Edoardo Guerriero
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-02-03T17:41:33.063Z
Comments.Text: @EdoardoGuerriero I've just edited my question; In addition, I don't have any specific expectations from the performance of the model, I actually looking for a reasonable result.
Comments.UserDisplayName: ShirinJZ
Tags: <deep-learning><keras><multiclass-classification>
Title: Low accuracy and high loss in multi-class classification
UserDisplayName: ShirinJZ
ThreadText: # Low accuracy and high loss in multi-class classification
  
  (Asked by: username_0 on 2022-02-03)
  
  I'm trying to classify images in 17 flowers dataset which consist of 1360 images of 17 classes (80 images per class); I have to use DNNs only therefore I made my model with the following settings:
  images_net = models.Sequential([layers.Dense(300,input_dim = 3072, activation='relu'),
                                      layers.Dense(30,activation='relu'),
                                      layers.Dense(17,activation='softmax')]);
  
  images_net.compile(optimizer='SGD', loss='categorical_crossentropy',metrics=['accuracy']);
  
  my_net = images_net.fit(x_train,y_train,validation_data=(x_test,y_test),batch_size=32,epochs=10)
  
  
  finally, when I evaluate my model I get the following result:
  
  Can anyone explain the result and what the problem is with these settings?
  
  **Tags:** deep-learning, keras, multiclass-classification
  > **Comments:**
  > **username_1**: Hard to help you without more information. What images are you trying to classify, what are the stats of the dataset your using (e.g. size), do you have an expectation about the final performance of the model, i.e. are you trying to replicate some results or just trying your luck? Also loss and metrics are easier to understand when plotted in separate graphs. For now the only striking thing is that you're using a dense neural net rather than a CNN, any reason for that?  
  > **username_0**: @EdoardoGuerriero I've just edited my question; In addition, I don't have any specific expectations from the performance of the model, I actually looking for a reasonable result.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2022-02-03. Score: 1
  
  Your model is completely underfit
  Reasons:
  
  You have a very small neural network that can't generalize your problem.
  you mentioned 17 classes but in the last layers, you are specifying 16 class layers. Dense(16,activation='softmax') try to fix this.
  If there is a class imbalance you have to remove this which may make your results worst.
  Add more epochs after adding more layers or use pre-trained models.
  
  Try this code and models:
  base_model = ResNet50V2(weights='imagenet', include_top=False, input_shape=(512,512,3))
   
  for layer in base_model.layers:
      layer.trainable = False
  x = GlobalAveragePooling2D()(base_model.output)
  
  prediction = Dense(17, activation='softmax')(x)
  model = Model(inputs=base_model.input, outputs=prediction)
  model.compile(optimizer = 'adam' , loss='categorical_crossentropy', metrics = ['accuracy'])
  model.summary()
  history = model.fit(x_train,y_train,validation_data=(x_test,y_test),batch_size=32,epochs=10)
  
  Evaulate Model:
  print(history.history.keys())
  #  "Accuracy"
  plt.plot(history.history['accuracy'])
  plt.plot(history.history['val_accuracy'])
  plt.title('model accuracy')
  plt.ylabel('accuracy')
  plt.xlabel('epoch')
  plt.legend(['train', 'validation'], loc='upper left')
  plt.show()
  # "Loss"
  plt.plot(history.history['loss'])
  plt.plot(history.history['val_loss'])
  plt.title('model loss')
  plt.ylabel('loss')
  plt.xlabel('epoch')
  plt.legend(['train', 'validation'], loc='upper left')
  plt.show()
  
  > **Comments:**
  > **username_3**: Hard to say without seeing the data, but the model has already 0.9 million trainable parameters so isn't super simple either. But it has very few layers and no convolutions at all, which doesn't seem ideal. But I agree with all of your other points.  
  > **username_2**: share your code I will let them with better accuracy  
  
  ---
  
  