«Нет градиентов для любой переменной» при попытке обучить мой кодировщик - PullRequest
1 голос
/ 02 апреля 2019

Я пытаюсь построить Двунаправленный GAN (GAN, который одновременно изучает обратное отображение в скрытое пространство). По некоторым причинам, пытаясь вычислить градиенты для моих кодировщиков, я получаю сообщение об ошибке «Градиенты не указаны ни для одной переменной». Но как ни странно, это работает как для моего генератора, так и для дискриминатора, хотя все они основаны на одной архитектуре.

def _add_optims(self, optims: dict):
    """
    Adds optims to model that are to be used by optimizers or during training
    Parameters
    ----------
    optim: dict
        dictionary containing all optimizers, optimizers should be of Type[tf.train.Optimizer]
    """
    if self._optims is not None and len(optims) != 0:
        logging.warning('Change of optims is not yet supported')
        pass
        #raise NotImplementedError()
    elif self._optims is not None and len(optims) == 0:
        pass
    else:
        self._optims = optims

            optim_gen = self._optims['gen']
            grads_gen = optim_gen.compute_gradients(self._losses['total_gen'], var_list=self.gen.trainable_variables)
            step_gen = optim_gen.apply_gradients(grads_gen)

            optim_discr = self._optims['discr']
            grads_discr = optim_discr.compute_gradients(self._losses['total_discr'], var_list=self.discr.trainable_variables)
            step_discr = optim_discr.apply_gradients(grads_discr)

            optim_enc = self._optims['enc']
            grads_enc = optim_enc.compute_gradients(self._losses['total_enc'], var_list=self.enc.trainable_variables)
            step_enc = optim_enc.apply_gradients(grads_enc)


            steps = tf.group([step_gen, step_enc, step_discr])

            self.outputs_train.append(steps)

Мои результаты отладки: Из моего кодировщика

[(None, <tf.Variable 'conv2d...e=float32>), (None, <tf.Variable 'batch_...e=float32>), (None, <tf.Variable 'batch_...e=float32>), (None, <tf.Variable 'sequen...e=float32>), (None, <tf.Variable 'sequen...e=float32>), (None, <tf.Variable 'sequen...e=float32>), (None, <tf.Variable 'sequen...e=float32>), (None, <tf.Variable 'sequen...e=float32>), (None, <tf.Variable 'sequen...e=float32>), (None, <tf.Variable 'sequen...e=float32>), (None, <tf.Variable 'sequen...e=float32>), (None, <tf.Variable 'sequen...e=float32>), (None, <tf.Variable 'sequen...e=float32>), (None, <tf.Variable 'sequen...e=float32>), ...]

Из моего генератора

[(<tf.Tensor 'gradient...e=float32>, <tf.Variable 'dense/...e=float32>), (<tf.Tensor 'gradient...e=float32>, <tf.Variable 'dense/...e=float32>), (<tf.Tensor 'gradient...e=float32>, <tf.Variable 'sequen...e=float32>), (<tf.Tensor 'gradient...e=float32>, <tf.Variable 'sequen...e=float32>), (<tf.Tensor 'gradient...e=float32>, <tf.Variable 'sequen...e=float32>), (<tf.Tensor 'gradient...e=float32>, <tf.Variable 'sequen...e=float32>), (<tf.Tensor 'gradient...e=float32>, <tf.Variable 'sequen...e=float32>), (<tf.Tensor 'gradient...e=float32>, <tf.Variable 'sequen...e=float32>), (<tf.Tensor 'gradient...e=float32>, <tf.Variable 'sequen...e=float32>), (<tf.Tensor 'gradient...e=float32>, <tf.Variable 'sequen...e=float32>), (<tf.Tensor 'gradient...e=float32>, <tf.Variable 'sequen...e=float32>), (<tf.Tensor 'gradient...e=float32>, <tf.Variable 'sequen...e=float32>), (<tf.Tensor 'gradient...e=float32>, <tf.Variable 'sequen...e=float32>), (<tf.Tensor 'gradient...e=float32>, <tf.Variable 'sequen...e=float32>), ...]
...