#python #tensorflow #keras #deep-learning
#питон #tensorflow #keras #глубокое обучение
Вопрос:
попытка изменить форму тензорного слоя dense1 с (None, 13)
(None, 1, 13)
фрагмента кода на фрагмент кода
dense1= Dense(13, activation='relu')
tf.expand_dims(dense1, axis=1)
И это ошибка
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-3-82c32af7a088> in <module>()
----> 1 tf.expand_dims(dense1, axis=1)
10 frames
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/constant_op.py in convert_to_eager_tensor(value, ctx, dtype)
96 dtype = dtypes.as_dtype(dtype).as_datatype_enum
97 ctx.ensure_initialized()
---> 98 return ops.EagerTensor(value, ctx.device_name, dtype)
99
100
ValueError: Attempt to convert a value (<tensorflow.python.keras.layers.core.Dense object at 0x7f58f41d9b00>) with an unsupported type (<class 'tensorflow.python.keras.layers.core.Dense'>) to a Tensor.
Ответ №1:
Попробуйте обернуть его в TimeDistributed
слой:
import tensorflow as tf
model = tf.keras.Sequential([
tf.keras.layers.TimeDistributed(tf.keras.layers.Dense(13, activation='relu'),
input_shape=[1, 13])])
model.build(input_shape=[13])
model.summary()
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
time_distributed_3 (TimeDist (None, 1, 13) 182
=================================================================
Total params: 182
Trainable params: 182
Non-trainable params: 0
_________________________________________________________________