У меня есть модель, которая должна обрабатывать потоковое видео, в котором каждый кадр представлен в виде массива из 63 чисел, shape у каждого массива (63,). Я написал модель на TensorFlow. Вот код:
def define_model():
inputs = Input(shape=(63,))
f1 = Embedding(8, 256, mask_zero=True)(inputs)
f2 = Dropout(0.5)(f1)
f3 = LSTM(256)(f2)
f4 = Dense(256, activation='relu')(f3)
outputs = Dense(8, activation='softmax')(f4)
model = Model(inputs=inputs, outputs=outputs)
model.compile(loss='categorical_crossentropy', optimizer='adam')
# summarize model
print(model.summary())
plot_model(model, to_file='model.png', show_shapes=True)
return model
model=define_model()
epochs=10
dataset='C:/Users/Admin/Documents/Volume/Dataset'
steps=len(os.listdir(dataset))
for i in range(epochs):
generator = generate(landmarks)
model.fit(generator, epochs=1, steps_per_epoch= steps, verbose=1)
model.save("models/model_" + str(i) + ".h5")
Когда я пытаюсь запустить этот код, выдается следующая ошибка:
ValueError: in user code:
c:\users\admin\appdata\local\programs\python\python39\lib\site-packages\keras\engine\training.py:853 train_function *
return step_function(self, iterator)
c:\users\admin\appdata\local\programs\python\python39\lib\site-packages\keras\engine\training.py:842 step_function **
outputs = model.distribute_strategy.run(run_step, args=(data,))
c:\users\admin\appdata\local\programs\python\python39\lib\site-packages\tensorflow\python\distribute\distribute_lib.py:1286 run
return self._extended.call_for_each_replica(fn, args=args, kwargs=kwargs)
c:\users\admin\appdata\local\programs\python\python39\lib\site-packages\tensorflow\python\distribute\distribute_lib.py:2849 call_for_each_replica
return self._call_for_each_replica(fn, args, kwargs)
c:\users\admin\appdata\local\programs\python\python39\lib\site-packages\tensorflow\python\distribute\distribute_lib.py:3632 _call_for_each_replica
return fn(*args, **kwargs)
c:\users\admin\appdata\local\programs\python\python39\lib\site-packages\keras\engine\training.py:835 run_step **
outputs = model.train_step(data)
c:\users\admin\appdata\local\programs\python\python39\lib\site-packages\keras\engine\training.py:788 train_step
loss = self.compiled_loss(
c:\users\admin\appdata\local\programs\python\python39\lib\site-packages\keras\engine\compile_utils.py:201 __call__
loss_value = loss_obj(y_t, y_p, sample_weight=sw)
c:\users\admin\appdata\local\programs\python\python39\lib\site-packages\keras\losses.py:141 __call__
losses = call_fn(y_true, y_pred)
c:\users\admin\appdata\local\programs\python\python39\lib\site-packages\keras\losses.py:245 call **
return ag_fn(y_true, y_pred, **self._fn_kwargs)
c:\users\admin\appdata\local\programs\python\python39\lib\site-packages\tensorflow\python\util\dispatch.py:206 wrapper
return target(*args, **kwargs)
c:\users\admin\appdata\local\programs\python\python39\lib\site-packages\keras\losses.py:1665 categorical_crossentropy
return backend.categorical_crossentropy(
c:\users\admin\appdata\local\programs\python\python39\lib\site-packages\tensorflow\python\util\dispatch.py:206 wrapper
return target(*args, **kwargs)
c:\users\admin\appdata\local\programs\python\python39\lib\site-packages\keras\backend.py:4839 categorical_crossentropy
target.shape.assert_is_compatible_with(output.shape)
c:\users\admin\appdata\local\programs\python\python39\lib\site-packages\tensorflow\python\framework\tensor_shape.py:1161 assert_is_compatible_with
raise ValueError("Shapes %s and %s are incompatible" % (self, other))
ValueError: Shapes (None, 1) and (None, 8) are incompatible
Я вижу, что форма (None, 8) есть у выходного слоя, но откуда там форма (None,1)?
Вот моя модель: