【发布时间】:2020-08-31 17:01:45
【问题描述】:
我正在使用 MobileNet 的迁移学习,然后将提取的特征发送到 LSTM 进行视频数据分类。
当我使用 image_dataset_from_directory() 设置训练、测试、验证数据集时,图像被调整为 (224,224)。
编辑: 所以我需要填充数据序列,但是这样做时会出现以下错误,我不太确定在使用 image_dataset_from_directory() 时该怎么做:
train_dataset = sequence.pad_sequences(train_dataset, maxlen=BATCH_SIZE, padding="post", truncating="post")
InvalidArgumentError: assertion failed: [Unable to decode bytes as JPEG, PNG, GIF, or BMP]
[[{{node decode_image/cond_jpeg/else/_1/decode_image/cond_jpeg/cond_png/else/_20/decode_image/cond_jpeg/cond_png/cond_gif/else/_39/decode_image/cond_jpeg/cond_png/cond_gif/Assert/Assert}}]] [Op:IteratorGetNext]
我检查了 train_dataset 类型:
<BatchDataset shapes: ((None, None, 224, 224, 3), (None, None)), types: (tf.float32, tf.int32)>
全局变量:
TARGETX = 224
TARGETY = 224
CLASSES = 3
SIZE = (TARGETX,TARGETY)
INPUT_SHAPE = (TARGETX, TARGETY, 3)
CHANNELS = 3
NBFRAME = 5
INSHAPE = (NBFRAME, TARGETX, TARGETY, 3)
手机网功能:
def build_mobilenet(shape=INPUT_SHAPE, nbout=CLASSES):
# INPUT_SHAPE = (224,224,3)
# CLASSES = 3
model = MobileNetV2(
include_top=False,
input_shape=shape,
weights='imagenet')
base_model.trainable = True
output = GlobalMaxPool2D()
return Sequential([model, output])
LSTM 函数:
def action_model(shape=INSHAPE, nbout=3):
# INSHAPE = (5, 224, 224, 3)
convnet = build_mobilenet(shape[1:])
model = Sequential()
model.add(TimeDistributed(convnet, input_shape=shape))
model.add(LSTM(64))
model.add(Dense(1024, activation='relu'))
model.add(Dropout(.5))
model.add(Dense(512, activation='relu'))
model.add(Dropout(.5))
model.add(Dense(128, activation='relu'))
model.add(Dropout(.5))
model.add(Dense(64, activation='relu'))
model.add(Dense(nbout, activation='softmax'))
return model
model = action_model(INSHAPE, CLASSES)
model.summary()
Model: "sequential_16"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
time_distributed_6 (TimeDist (None, 5, 1280) 2257984
_________________________________________________________________
lstm_5 (LSTM) (None, 64) 344320
_________________________________________________________________
dense_45 (Dense) (None, 1024) 66560
_________________________________________________________________
dropout_18 (Dropout) (None, 1024) 0
_________________________________________________________________
dense_46 (Dense) (None, 512) 524800
_________________________________________________________________
dropout_19 (Dropout) (None, 512) 0
_________________________________________________________________
dense_47 (Dense) (None, 128) 65664
_________________________________________________________________
dropout_20 (Dropout) (None, 128) 0
_________________________________________________________________
dense_48 (Dense) (None, 64) 8256
_________________________________________________________________
dense_49 (Dense) (None, 3) 195
=================================================================
Total params: 3,267,779
Trainable params: 3,233,667
Non-trainable params: 34,112
【问题讨论】:
-
数据集。如果只是一批图像,那就是问题所在。
-
根据错误的说法。您正在尝试提供类似 (32, 224, 224, 3) 的内容,但您的模型需要 (32, 5, 224, 224, 3)
-
那么必须来自INSHAPE,它的形状应该是(224,224,3)。我正在阅读一篇文章中的代码,他们将帧数作为序列发送到他们的模型中。我会试试看它是否有效。
标签: python tensorflow keras deep-learning