【问题标题】:ValueError:Attempt to convert a value (<tf.keras.layers.core.Dense) with an unsupported type (<class 'tf.keras.layers.core.Dense'>) to a TensorValueError:尝试将具有不受支持的类型(<class 'tf.keras.layers.core.Dense'>)的值(<tf.keras.layers.core.Dense)转换为张量
【发布时间】:2020-12-19 00:47:04
【问题描述】:

试图将dense1张量层的形状从(None, 13)更改为(None, 1, 13) 代码sn-p

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.

【问题讨论】:

    标签: python tensorflow keras deep-learning


    【解决方案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
    _________________________________________________________________
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-05
      • 2020-09-09
      相关资源
      最近更新 更多