Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Keras与tensorflow_Tensorflow_Keras - Fatal编程技术网

Keras与tensorflow

Keras与tensorflow,tensorflow,keras,Tensorflow,Keras,我有一个模型,我试图定制一点 我想用Tensorflow模式运行它 from model import Deeplabv3 import tensorflow as tf tf.enable_eager_execution() model = Deeplabv3(weights='pascal_voc', input_shape=(200,200,3), backbone='mobilenetv2', classes=64) batch = tf.zeros((1,200,200,3)) f

我有一个模型,我试图定制一点

我想用Tensorflow模式运行它

from model import Deeplabv3
import tensorflow as tf
tf.enable_eager_execution()

model = Deeplabv3(weights='pascal_voc', input_shape=(200,200,3), backbone='mobilenetv2', classes=64)
batch = tf.zeros((1,200,200,3))
f = model(batch)
但是,这会产生错误:

模型.py“,第236行,在_倒置的_res_块中 in_channels=inputs._keras_shape[-1]AttributeError:'DeferredTensor'对象没有属性'_keras_shape'

这是关于代码的这一部分

def _inverted_res_block(inputs, expansion, stride, alpha, filters, block_id, skip_connection, rate=1):
    in_channels = inputs._keras_shape[-1]
    #in_channels = inputs.get_shape()[-1].value
    #in_channels = tf.shape(inputs)[-1]

    import pdb;pdb.set_trace()

    pointwise_conv_filters = int(filters * alpha)
    pointwise_filters = _make_divisible(pointwise_conv_filters, 8)
    x = inputs

    prefix = 'expanded_conv_{}_'.format(block_id)
    if block_id:
        # Expand

        x = Conv2D(expansion * in_channels, kernel_size=1, padding='same',
                   use_bias=False, activation=None,
                   name=prefix + 'expand')(x)
如何解决这个问题?

正如所指出的:

  • tf.keras
    (包含在TensorFlow中)支持即时执行,而
    keras
    模块不支持
  • tf.keras
    实现了
    keras
    API规范,因此它应该是使用
    keras
    的任何程序的替代品(例如,将对
    keras.Model
    的引用更改为
    tf.keras.Model
    )。此外,它还支持TensorFlow中的即时执行

    • 我做了以下更改:

      改为此行:in_channels=inputs.shape[-1]。value 或另一行:输入

      我在_channels=inputs.shape.as_list()[-1]中使用了另一个:


      它对我很有用。

      虽然eager execution与
      tf.keras
      兼容(并推荐使用),但我认为这不会扩展到
      keras
      模块。