contrastive-unpaired-translation icon indicating copy to clipboard operation
contrastive-unpaired-translation copied to clipboard

data_dependent_initialization error when using cycle_gan model

Open LumenPallidium opened this issue 5 years ago • 3 comments

I'm currently comparing how the various included models perform for my dataset. While the standard CUT and stylegan models both worked, when I try using the option --model cycle_gan I get the error:

Type Error: data_dependent_initialize() takes 1 positional argument but 2 were given

This seems to be due to the fact that in models/cycle_gan_model.py on line 193 data_dependent_initalize is defined as:

    def data_dependent_initialize(self):
        return

so that it doesn't have the arguments (self, data) as it seems to be intended to.

I tried modifying the function to be the same as the base model class (which simply passes/does nothing), assuming that the cycle_gan model did not need this type of data initialization but that did not help.

I understand I could just use the existing cyclegan repo, but was hoping I could use this one as a "one-stop shop".

LumenPallidium avatar Oct 11 '20 05:10 LumenPallidium

I've fixed my issue. It does look like data_dependent_initialization can be converted to the base class version (just passing, no data dependent initialization). If you try to run the code after this, you will get an error that self.opt.amp does not exist. Looking at the code (~line 143 in the cycle_gan model):

        if self.opt.amp:
            with amp.scale_loss(loss_D, self.optimizer_D) as scaled_loss:
                scaled_loss.backward()

This parameter determines where NVIDIA Apex's amp function will be used (if at all). To remedy this, all I did was add an option to the base options: parser.add_argument('--amp', type=util.str2bool, default=False, help='enables or disables automatic mixed precision')

If you don't want to install apex (it apparently can have issues with Windows), I don't think you need to, but you of course would need to ensure this parameter is always False.

After making these changes (reverting data_dependent_initialization to the base class function and adding amp to the command line options), the cycle_gan model runs fine (at least to iteration 100, I won't try a full run until later tonight).

LumenPallidium avatar Oct 24 '20 21:10 LumenPallidium

@LumenPallidium thanks a lot your suggestions also worked for me.

BartvanMarrewijk avatar Jun 07 '21 13:06 BartvanMarrewijk

The same problem

    model.data_dependent_initialize(data)
TypeError: data_dependent_initialize() takes 1 positional argument but 2 were given

My dataset:

ls datasets/maps/
test  testA  testB  train  trainA  trainB  val  valA  valB

b4zz4 avatar Dec 03 '21 01:12 b4zz4