I am pretty new to keras and machine learning, but my code is not working and I am pretty sure it is because of my model. I am trying to train my model with a csv file that has my images all flattened into one row. Essentially, each row of data is one image. However, this error message keeps popping up
ValueError: Exception encountered when calling layer "sequential" (type Sequential).
Input 0 of layer "dense3" is incompatible with the layer: expected min_ndim=2, found ndim=1. Full shape received: (4096,)
Call arguments received by layer "sequential" (type Sequential):
• inputs=tf.Tensor(shape=(4096,), dtype=uint8)
• training=False
• mask=None
I have looked online and tried a lot of things, but I am new, so I do not completely understand everything. The image is 64x64, so I assumed that the columns were the input size.... so set the input size equal to 6464 and also changed the predict batch size to be 6464 that way it matches (since I am getting the real-time flattened image to be predicted). It solved the problem for the first layer (the input layer), but now the dense layers after are not working. I also have the image label at the first index of every row on the csv file.
def modelTraining():
model = keras.models.Sequential()
model.add(keras.Input(shape=(4096,)))
model.add(keras.layers.Dense(4096, activation='relu', name = "dense2"), )
model.add(keras.layers.Dense(1, activation='softmax', name = "dense3", ))
model.compile(optimizer='rmsprop',
loss='binary_crossentropy',
metrics=['accuracy'])
#Get our training image data
trainingImageMatrix = []
trainingLabelsArray = []
temp = 0
with open(r'C:\Users\Jason\Desktop\signLanguage\testOpenCV\training.csv', 'r', newline='') as myFile:
reader = csv.reader(myFile, delimiter=',')
for row in reader:
temp+=1
imageDataToAdd = np.zeros(4096)
for i in range (1, 4097):
imageDataToAdd[i - 1] = row[i]
trainingLabelsArray.append(int(row[0])) #need to get the first index of every row
trainingImageMatrix.append(imageDataToAdd)
print("reading row: "+str(temp))
#if temp >=10:
#break
trainingImageMatrix = np.array(trainingImageMatrix)
trainingLabelsArray = np.array(trainingLabelsArray)
model.fit(trainingImageMatrix, trainingLabelsArray, epochs = 20, batch_size = 4096)
return model
model.predict(grayFrame.flatten(), batch_size = 4096)
this line is in another part of my code, but this is the predict I am using atm.
Would appreciate some help and clarification on how to specify the size and how the layers should be customized for my task.