如何设置子类模型的输入形状?

时间:2019-03-26 02:06:25

标签: build keras subclass

def呼叫(self,x):

第一次调用我的模式(子类)时,无法检查batch_size(无)。

如果要连接多个图层,则模型会检查输入形状。

但不能

如何设置子类模型的输入形状?

model.build(input_shape),但无效。

def call(self,x):
    """ Forward """
    # [x,y]=Lambda(lambda x:[x[0],x[1]], output_shape=[-1,self.opt.ncond,self.opt.nc,self.opt.height,self.opt.width])(x)
    inputs = Reshape((self.opt.ncond * self.opt.nc, self.opt.height, self.opt.width))(x)  # batch_size, shape
    target = Reshape((self.opt.npred * self.opt.nc, self.opt.height, self.opt.width))(self.y)
    g_pred_v = K.variable(self.deterministic(inputs), name="g_pred_v")
    r=K.abs(g_pred_v-target) # residual
    z=self.phi_network_conv(r)
    s = self.deterministic.get_layer()[0](inputs)
    h=concatenate([s,z], axis=1) # concatenate
    # shape=K.int_shape(s)
    # h=Reshape((shape[1]*2, shape[2],shape[3]))(h)
    pred_f = self.f_network_decoder(h)
    return pred_f

def get_target(self,y):
    # input layer
    self.y=y

当我第一次尝试“ train_on_batch”时,在前移过程中,输入形状很清晰,而不是[无,通道,高度,宽度]

0 个答案:

没有答案
相关问题