Code Monkey home page Code Monkey logo

Comments (5)

williamyang1991 avatar williamyang1991 commented on July 17, 2024

I changed it to jpg because I thought the format of the picture might be a problem, but there must be a problem.

So the error occurs when you use jpg or png?
The code uses mean and std to adjust 3 channels of your data.

RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton dimension 0

It seems that your data has 4 channels.

    transform2 = transforms.Compose(
    [
        transforms.ToTensor(),
        transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5), inplace=True),
    ])     

File "finetune_dualstylegan.py", line 529, in
Simg = transform2(Simg).unsqueeze(dim=3)

My original code is Simg = transform2(Simg).unsqueeze(dim=0)
Did you make modifications to the code, which leads to the error?

from dualstylegan.

hw1204 avatar hw1204 commented on July 17, 2024

@williamyang1991 It was originally a png format, but I changed it to jpg, but there is still an error. I tried your original code, but it's the same! Do you think the png format is a problem?

from dualstylegan.

williamyang1991 avatar williamyang1991 commented on July 17, 2024

you can add
print(np.array(Simg).shape) before
Simg = transform2(Simg).unsqueeze(dim=0)
to see the shape of your Simg.
It should be (1024, 1024, 3)
otherwise, there is something wrong with your style image.

from dualstylegan.

hw1204 avatar hw1204 commented on July 17, 2024

Alpha Channel was the problem! Thanks for letting me know. One question is that input image is definitely channel 3, but Simg is still channel 4. Can I assume there was a malfunction in the middle?

from dualstylegan.

williamyang1991 avatar williamyang1991 commented on July 17, 2024

My code is just read the image and transform it.

Simg = Image.open(os.path.join(path, filename))
Simg = transform2(Simg).unsqueeze(dim=0)

It was originally a png format, but I changed it to jpg

It should be that you incorrectly changed png to jpg without discarding its alpah channel.

from dualstylegan.

Related Issues (20)

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.