模型训练-形状输入为,但得到5



我正试图用我自己(脸(的多张图像(14张(来训练模型,但我一直比需要的多得到一层,因为它给出了null。模型在第一个字段中显示null。我正在尝试制作一个用于图像/物体/人脸识别的CNN。我真的需要帮助,我们将不胜感激。

错误:

Error when checking input: expected conv2d_Conv2D1_input to have 4 dimension(s). but got array with shape 14,1,1280,720,3

型号:

__________________________________________________________________________________________
Layer (type)                Input Shape               Output shape              Param #   
==========================================================================================
conv2d_Conv2D1 (Conv2D)     [[null,1280,720,3]]       [null,1278,718,16]        448       
__________________________________________________________________________________________
max_pooling2d_MaxPooling2D1 [[null,1278,718,16]]      [null,639,359,16]         0
__________________________________________________________________________________________
conv2d_Conv2D2 (Conv2D)     [[null,639,359,16]]       [null,637,357,32]         4640
__________________________________________________________________________________________
max_pooling2d_MaxPooling2D2 [[null,637,357,32]]       [null,318,178,32]         0
__________________________________________________________________________________________
flatten_Flatten1 (Flatten)  [[null,318,178,32]]       [null,1811328]            0
__________________________________________________________________________________________
dense_Dense1 (Dense)        [[null,1811328]]          [null,10]                 18113290
==========================================================================================
Total params: 18118378
Trainable params: 18118378
Non-trainable params: 0

代码:

const trainingData = [];
const trainingLabels = [];

fs.readdirSync("./data/train/").forEach((file) => {
const image = tf.node.decodeImage(fs.readFileSync(`./data/train/${file}`)).resizeNearestNeighbor([1280,720])
.toFloat()
.div(tf.scalar(255.0))
.expandDims();
trainingData.push(image);
trainingLabels.push("Ewen");
});

const model = tf.sequential();
model.add(tf.layers.conv2d({
inputShape: [1280,720,3],
kernelSize: 3,
filters: 16,
strides: 1,
activation: 'relu'
}));
model.add(tf.layers.maxPooling2d({
poolSize: [2, 2]
}))
model.add(tf.layers.conv2d({
kernelSize: 3,
filters: 32,
strides: 1,
activation: 'relu'
}));
model.add(tf.layers.maxPooling2d({
poolSize: [2, 2]
}))
model.add(tf.layers.flatten());
model.add(tf.layers.dense({
units: 10,
activation: 'softmax'
}))
model.compile({
optimizer: "adam",
loss: "categoricalCrossentropy",
metrics: ["accuracy"],
});
logger.success("Model compiled: ");
model.summary();

输入的形状(14,1,1280,720,3(有5个维度。我认为你应该尝试使用一个整形函数,这样它就变成了4个维度,也就是说,只需要去掉值为1的维度。我不完全确定你使用的是什么语言,但下面是代码应该是什么样子:

input_imgs = reshape(input_imgs, (14, 1280, 720, 3));

您只需要查找正在使用的语言和框架的整形函数。希望这能有所帮助!

相关内容

  • 没有找到相关文章

最新更新