简体   繁体   English

输入图像列表的 CNN model 输出 [int,int,float] 列表

[英]CNN model that inputs image list outputs a list of [int,int,float]

I'm still new to deep learning and CNN and I don't know what this error is so anyone can help me?我对深度学习和 CNN 还是新手,我不知道这个错误是什么,所以有人可以帮助我吗?

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.这个 model 旨在获取图像数组的输入,而 output 是一个项目列表,每个项目都包含一个 int、int、float,我不能使 model 不包含任何错误。

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]. ValueError:尺寸必须相等,但对于“{{node mean_squared_error/SquaredDifference}} = SquaredDifference[T=DT_FLOAT](sequential/dense_1/Relu, mean_squared_error/Cast)”,输入形状为 162 和 3:[?,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:n_number就是你的model的output的号码:

model.add(Dense(n_number,activation='sigmoid'))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM