适合视频分类的输入形状,使用文件夹图片

问题描述 投票:0回答:2

这是问题所在。我有多个文件夹,每个文件夹有 37 张照片,一张照片有 126 个关键点,我怎么能重塑输入形状,因为我说错了

ValueError: Shapes (None, 1) and (None, 5) are incompatible

input shape

如果需要,模型结构

from tensorflow.keras.models import  Sequential
from  tensorflow.keras.layers import LSTM,Dense
from  tensorflow.keras.callbacks import TensorBoard
import  tensorflow as tf


log_dir = os.path.join('logs')
callback = TensorBoard(log_dir=log_dir)

model = Sequential()

model.add(LSTM(64,input_shape=(37,126,),return_sequences=True,activation='relu'))
model.add(LSTM(128,return_sequences=True,activation='relu'))
model.add(LSTM(64,return_sequences=False,activation='relu'))
model.add(Dense(64,activation='relu'))
model.add(Dense(32, activation='relu'))

model.add(Dense(class_label.shape[0],activation='softmax'))


model.summary()

我想知道我应该去哪里检查,谢谢大家的回答

python deep-learning
2个回答
0
投票

这是我尝试复制你的代码,假设有 5 个输出类(为了我的理智,有一个额外的 Input 层:What is the advantage of using an InputLayer (or an Input) in a Keras model with Tensorflow tensors?) :

from tensorflow.keras import Input
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import LSTM, Dense
from tensorflow.keras.callbacks import TensorBoard
import tensorflow as tf

#log_dir = os.path.join('logs')
#callback = TensorBoard(log_dir=log_dir)

model = Sequential()
model.add(Input(shape = (37, 126,)))
model.add(LSTM(64, input_shape = (37, 126,), return_sequences = True, activation = 'relu', name = 'lstm1'))
model.add(LSTM(128, return_sequences = True, activation = 'relu', name = 'lstm2'))
model.add(LSTM(64, return_sequences = False, activation = 'relu', name = 'lstm3'))
model.add(Dense(64, activation = 'relu', name = 'd1'))
model.add(Dense(32, activation = 'relu', name = 'd2'))

model.add(Dense(5, activation = 'softmax', name = 'out'))

model.summary()

结果如下图:

Model: "sequential_2"
_________________________________________________________________
 Layer (type)                Output Shape              Param #   
=================================================================
 lstm1 (LSTM)                (None, 37, 64)            48896     
                                                                 
 lstm2 (LSTM)                (None, 37, 128)           98816     
                                                                 
 lstm3 (LSTM)                (None, 64)                49408     
                                                                 
 d1 (Dense)                  (None, 64)                4160      
                                                                 
 d2 (Dense)                  (None, 32)                2080      
                                                                 
 out (Dense)                 (None, 5)                528       
                                                                 
=================================================================
Total params: 203,888
Trainable params: 203,888
Non-trainable params: 0
_________________________________________________________________

也许问题不在于您的输入形状,而在于输出?如果您的图像是正确的,该模型会将图像预测为 ?类,但只验证单个类,因此不能直接比较。考虑先将 ground truth 和预测结果填充为相同大小。


0
投票

感谢@Nam Nguyen Hoang .

是关于输出的问题。 我猜这个错误出现了,因为我的旧目标输出是

[0,4,26,2,3]
,它不是排序的整数目标。将输出更改为排序的整数后,我修复了这个错误

© www.soinside.com 2019 - 2024. All rights reserved.