Giter Site home page Giter Site logo

Code broken in backward about vae-gan HOT 4 OPEN

FrancescoMandru avatar FrancescoMandru commented on September 9, 2024 4
Code broken in backward

from vae-gan.

Comments (4)

ry85 avatar ry85 commented on September 9, 2024

Hi,

The code should work fine. There might some difference with respect to the python version or similar to that. The error you are getting is not an uncommon error, did you tried to google it. I think modifying the version should work.

from vae-gan.

ILYSHI avatar ILYSHI commented on September 9, 2024

It's rather common error, i found it in several VAE-GAN models.

from vae-gan.

GloryyrolG avatar GloryyrolG commented on September 9, 2024

Hi,

The code should work fine. There might some difference with respect to the python version or similar to that. The error you are getting is not an uncommon error, did you tried to google it. I think modifying the version should work.

Could you please provide your environment, i.e., the requirements of this repo code?

from vae-gan.

wqzdhrdhr avatar wqzdhrdhr commented on September 9, 2024

Hi,

The code should work fine. There might some difference with respect to the python version or similar to that. The error you are getting is not an uncommon error, did you tried to google it. I think modifying the version should work.

I encountered the same problem, my environment is pytorch1.7+python3.9. I guess this is because in the newer version of pytorch, .step() directly changes the parameters in the graph, instead of creating a clone like in the old version. So I tried to put all optimizer.step() after all loss.backward() was completed.

        `net.zero_grad()
        # encoder
        loss_encoder.backward(retain_graph=True)  #someone likes to clamp the grad here: [p.grad.data.clamp_(-1,1) for p in net.encoder.parameters()]
        net.decoder.zero_grad()
        net.discriminator.zero_grad()

        if (train_dec and train_dis == True):
            loss_decoder.backward(retain_graph=True)
            net.discriminator.zero_grad()
            loss_discriminator.backward()
            optimizer_encoder.step()
            optimizer_decoder.step()
            optimizer_discriminator.step()
        #decoder
        if (train_dec == True and train_dis == False):
            loss_decoder.backward()  #[p.grad.data.clamp_(-1,1) for p in net.decoder.parameters()]
            optimizer_decoder.step()
            optimizer_encoder.step()
            optimizer_discriminator.step()


        #discriminator
        if (train_dec == False and train_dis == True):
            loss_discriminator.backward() 
            optimizer_encoder.step()
            optimizer_decoder.step()
            optimizer_discriminator.step()

        if (train_dec == False and train_dis == False):
            optimizer_encoder.step()`

from vae-gan.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.