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
Tensorflow 为什么这个模型还没有建立?_Tensorflow_Keras - Fatal编程技术网

Tensorflow 为什么这个模型还没有建立?

Tensorflow 为什么这个模型还没有建立?,tensorflow,keras,Tensorflow,Keras,我的代码类似于这样: class sub_sub_Block(tf.keras.Model): def __init__(self, kernel_size, filters): super(sub_sub_Block, self).__init__(name='') if req==True: self.layer1 = tf.keras.layers.Conv2D(filters1, (1, 1)) if inf==True: s

我的代码类似于这样:

class sub_sub_Block(tf.keras.Model):
  def __init__(self, kernel_size, filters):
    super(sub_sub_Block, self).__init__(name='')
    if req==True:
        self.layer1 = tf.keras.layers.Conv2D(filters1, (1, 1))

    if inf==True:
        self.layer2 = tf.keras.layers.Conv2D(filters, (1, 1))


  def call(self, input_tensor, training=False):
    x = self.layer1(input_tensor)
    x = self.layer2(x)

    return tf.nn.relu(x)

class sub_Block(tf.keras.Model):
  def __init__(self, kernel_size, filters):
    super(sub_Block, self).__init__(name='')
    if req==True:
        self.layer1 = sub_sub_Block(filters1, (1, 1))

    if inf==True:
        self.layer2 = tf.keras.layers.Conv2D(filters, (1, 1))


  def call(self, input_tensor, training=False):
    x = self.layer1(input_tensor)
    x = self.layer2(x)

    return tf.nn.relu(x)


class Block(tf.keras.Model):
  def __init__(self, kernel_size, filters):
    super(Block, self).__init__(name='')
    if req==True:
        self.layer1 = subBlock(filters1, (1, 1))

    if inf==True:
        self.layer2 = tf.keras.layers.Conv2D(filters, (1, 1))


  def call(self, input_tensor, training=False):
    x = self.layer1(input_tensor)
    x = self.layer2(x)

    return tf.nn.relu(x)

block = Block(1, [1, 2, 3])
print(block(tf.zeros([1, 2, 3, 3])))
print(block.summary())
错误消息为:

ValueError:此模型尚未构建。首先通过调用
Build()
或使用一些数据调用
fit()
来构建模型,或者指定 n
input_shape
参数位于第一层,用于自动生成

  • 如何解决这个问题
  • tf.keras.Model
    是否不能在其他
    tf.keras.Model
    块中