0

I am trying to classify geometric shapes with respect to certain properties (such as edgy forms vs. round forms). The output of my network is always either [1, 0] or [0, 1], even when the prediction is wrong. Is there a way to get useful softmax outputs (e.g [0.6, 0.4] if the prediction is unsure)? Ideally, I would like to read off the "obviousness" of the shapes' properties by the values of the softmax outputs (e.g. [1, 0] -> "The shape is very round." vs. [0.6, 0.4] -> "The shape is kind of round.").

You can find the architecture of my model in the code down below.

I would be very happy if someone could help me with this issue since it is my very first machine learning project.

Best regards, Valentin

import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout, Activation, Flatten, Conv2D, MaxPooling2D
import pickle
import numpy as np
import tensorflowjs as tfjs

X = pickle.load(open("Round.pickle", "rb"))
Y = pickle.load(open("Round.pickle", "rb"))

X = np.array(X/255.0)
Y = np.array(Y)

model = Sequential()
model.add(Conv2D(64, (3,3), input_shape = X.shape[1:]))
model.add(Activation("relu"))
model.add(MaxPooling2D(pool_size = (2,2)))

#model.add(Conv2D(64, (3,3)))
#model.add(Activation("relu"))
#model.add(MaxPooling2D(pool_size = (2,2)))

model.add(Flatten())
model.add(Dense(1024))
model.add(Activation("relu"))

model.add(Dense(512))
model.add(Activation("relu"))

model.add(Dense(2))
model.add(Activation("softmax"))


optimizer = tf.keras.optimizers.Adam(learning_rate=0.1)

model.compile(loss = "categorical_crossentropy", 
              optimizer = optimizer,
              metrics = ['accuracy'])

model.fit(X, Y, batch_size = 8, epochs = 5, validation_split = 0.1)

model.save('Round.model')

Valentin
  • 13
  • 2
  • You can try adding more `Conv2D` layers. To avoid extreme outputs, use regularization techniques like weight decay, dropout etc. – Shubham Panchal Jun 10 '21 at 12:23
  • Thank you for your tips. Adding a second Conv2D layer leads decreases the accuracy to only 50% (about random). I have just added a dropout layer between the two dense layers. Unfortunately, I still seem to get only [1, 0] predictions. Should I add more than just one dropout layer? Thank you very much! – Valentin Jun 10 '21 at 16:46

0 Answers0