我正在玩GAN进行图像任务,但在我的生成器中出现了这个错误

Traceback(最近一次调用最后一次):

文件“BannerGenerate.py”,第208行,在SeparateGANTrainer中(config,g_period = 6).train()

文件"/root/tensorflow_tangchuanxin/GAN/GAN.py",第118行, init model.g_loss,var_list = model.g_vars,name = 'g_min')

文件“/usr/lib/python2.7/site-packages/tensorflow/python/training/optimizer.py”,第350行,最小化([str(v)for _,v in grads_and_vars],loss))

ValueError:没有为任何变量提供渐变,检查图表中不支持渐变的ops,变量[“”......“”,“”]和丢失Tensor(“g_loss:0”,shape =( ),dtype = float32) .

这是我的代码的一部分 . 我无法弄清楚为什么图表上没有连接 .

def generator(self, img, img1):
    assert img is not None
    assert img1 is not None
    tmp_img = tf.concat([img,img1],axis=0)
    l = self.Resnet101(tmp_img)
    l = LinearWrap.tensor(l)
    l, l1 = tf.split(l, 2, axis=0)
    l = tf.concat([l,l1],3)
    with argscope([Conv2D, GlobalAvgPooling, InstanceNorm], data_format='NHWC'):
        x1 = Conv2D('conv_x', l, 1, kernel_shape=1, nl=tf.sigmoid, stride=1)
        x1 = GlobalAvgPooling('global_avg_pooling1', x1)
        y1 = Conv2D('conv_y', l, 1, kernel_shape=1, nl=tf.sigmoid, stride=1)
        y1 = GlobalAvgPooling('global_avg_pooling2', y1)
        height = Conv2D('conv_height', l, 1, kernel_shape=1, nl=tf.sigmoid, stride=1)
        height = GlobalAvgPooling('global_avg_pooling3', height)
        width = Conv2D('conv_width', l, 1, kernel_shape=1, nl=tf.sigmoid, stride=1)
        width = GlobalAvgPooling('global_avg_pooling4', width)
    #imgs_gen = tf.image.crop_and_resize(img, pos, tf.range(BATCH), tf.constant([HEIGHT,WIDTH]))
    #x1, y1, height, width = tf.split(pos, 4, axis=1)
    x1 = tf.cast(x1 * tf.constant(HEIGHT-1, shape=[BATCH,1], dtype=tf.float32), tf.int32)
    y1 = tf.cast(y1 * tf.constant(WIDTH-1, shape=[BATCH,1], dtype=tf.float32), tf.int32)
    height = tf.cast(height * tf.constant(HEIGHT-1, shape=[BATCH,1], dtype=tf.float32), tf.int32)
    width = tf.cast(width * tf.constant(WIDTH-1, shape=[BATCH,1], dtype=tf.float32), tf.int32)
    box_x = tf.split(x1, BATCH, axis=0)
    box_y = tf.split(y1, BATCH ,axis=0)
    box_h = tf.split(height, BATCH, axis=0)
    box_w = tf.split(width, BATCH, axis=0)
    img = tf.split(img, BATCH, axis=0)
    img1 = tf.split(img1, BATCH, axis=0)
    imgs_gen = []
    for i in range(BATCH):
        x = tf.to_int32(tf.squeeze(box_x[i]))
        y = tf.to_int32(tf.squeeze(box_y[i]))
        h = tf.to_int32(tf.squeeze(box_h[i]))
        w = tf.to_int32(tf.squeeze(box_w[i]))
        img1[i] = tf.image.resize_bilinear(img1[i], [h, w])
        img1[i] = tf.image.resize_bilinear(img1[i], [HEIGHT, WIDTH])
        mask = tf.ones_like(img1[i])
        zero_pad = tf.constant([[0,0]])
        h_pad = tf.concat([tf.reshape(tf.maximum(x-1,0),[1,1]), tf.reshape(HEIGHT-x-h,[1,1])], axis=1)
        w_pad = tf.concat([tf.reshape(tf.maximum(y-1,0),[1,1]), tf.reshape(WIDTH-y-w,[1,1])], axis=1)
        paddings = tf.concat([zero_pad, h_pad, w_pad, zero_pad], axis=0)
        img1[i] = tf.pad(img1[i], paddings)
        img1[i] = tf.reshape(img1[i],[1, HEIGHT, WIDTH, 3])
        mask = tf.pad(mask, paddings)
        img1[i] = img1[i] + img[i] - img[i] * mask
        imgs_gen.append(img1[i])
    imgs_gen = tf.concat(imgs_gen, axis=0)

    return imgs_gen