英文:
proper input shape for video classification ,use folder picture
问题
以下是要翻译的内容:
这里是问题。我有多个文件夹,每个文件夹有37张照片,每张照片有126个关键点,我该如何调整输入形状,因为我得到了一个错误,错误信息为ValueError: Shapes (None, 1) and (None, 5) are incompatible
。
如果需要模型结构如下:
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()
我想知道我应该检查哪里,感谢所有的回答。
英文:
Here are the problem issues.I have multiples folders ,each folder have 37 photos ,one photos have 126 keypoints,how can I reshape the input shape since I got error saying
ValueError: Shapes (None, 1) and (None, 5) are incompatible
the model structe if needed
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()
I want to know where i should check ,thank you for all the answer
答案1
得分: 1
这是我尝试复制您的代码,假设有5个输出类(为了保持清晰,我添加了额外的Input层: https://stackoverflow.com/questions/45217973/what-is-the-advantage-of-using-an-inputlayer-or-an-input-in-a-keras-model-with):
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
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
_________________________________________________________________
也许问题不在于您的输入形状,而是输出形状?如果您的图像是正确的,模型预测图像到?个类别,但只验证到一个类别,因此不能直接进行比较。首先考虑填充真实标签和预测结果以使它们具有相同的大小。
英文:
This is my attempt at replicating your code, assuming 5 output classes (with an extra Input layer for my sanity: https://stackoverflow.com/questions/45217973/what-is-the-advantage-of-using-an-inputlayer-or-an-input-in-a-keras-model-with):
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()
The result is as shown below:
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
_________________________________________________________________
Perhaps the problem is not with your input shape, but output? If your image is correct, the model predicts images into ? classes, but only validate to a single class, and thus can not be compared directly. Consider padding the ground truth and prediction result to be the same size first.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论