I'm still new to deep learning and CNN and I don't know what this error is so anyone can help me?
This model is designed to take input of image array and output is a list of items and each items contains an int,int,float and I cannot make a model than contains no error.
The error
ValueError: Dimensions must be equal, but are 162 and 3 for '{{node mean_squared_error/SquaredDifference}} = SquaredDifference[T=DT_FLOAT](sequential/dense_1/Relu, mean_squared_error/Cast)' with input shapes: [?,162], [?,54,3].
The code
import numpy as np
import os
from skimage import io
from keras.models import Sequential
from keras.layers import Conv2D, MaxPooling2D, Flatten, Dense
def SeperateDataFrameItems(imagesArray, maxCount):
tempList = []
finalList = []
ct = 0
for i in range(len(imagesArray)):
if imagesArray[i][0] != '#':
tempList.append(np.array([imagesArray[i][1], imagesArray[i][2], imagesArray[i][3]]))
ct = ct + 1
else:
for i in range(ct, maxCount):
tempList.append(np.array([-1,-1,-1]))
finalList.append(tempList)
tempList = []
ct = 0
return np.stack(finalList, axis=0)
def HandleDesigndata(start, end):
path = 'Designs/designs/'
all_images = []
for image_path in os.listdir(path):
img = io.imread(path + image_path, as_gray=True)
img = img.reshape([768, 607, 1])
all_images.append(img)
return np.array(all_images)
image_list = HandleDesigndata(100, 200)
circles_data = pd.read_csv('Data.csv')
circles_data = SeperateDataFrameItems(circles_data.to_numpy(), 54)
model = Sequential()
model.add(Conv2D(32, kernel_size=(3, 3), activation='relu', input_shape=(768, 607, 1)))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Flatten())
model.add(Dense(128, activation='relu'))
model.add(Dense(162, activation='relu'))
model.compile(optimizer='adam', loss='mse', metrics=['accuracy'])
model.fit(x=image_list, y=circles_data, batch_size=100, epochs=10, validation_split=0.1)```
You have to add a final dense layer before the compiler. And the n_number
is the number of the output of your model:
model.add(Dense(n_number,activation='sigmoid'))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.