为什么尚未建立此模型?

时间:2019-07-16 13:45:07

标签: 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:
        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()来构建模型,或指定一个   第一层中的input_shape个参数用于自动构建。

  1. 如何解决这个问题?
  2. tf.keras.Model不能在其他tf.keras.Model区块中吗?

0 个答案:

没有答案