Giter Site home page Giter Site logo

RuntimeError: Given groups=1, weight of size 16 3 1 1, expected input[3, 1, 128, 128] to have 3 channels, but got 1 channels instead about stylegan2-pytorch HOT 8 CLOSED

josephrocca avatar josephrocca commented on May 25, 2024
RuntimeError: Given groups=1, weight of size 16 3 1 1, expected input[3, 1, 128, 128] to have 3 channels, but got 1 channels instead

from stylegan2-pytorch.

Comments (8)

lucidrains avatar lucidrains commented on May 25, 2024 2

@josephrocca this is very helpful actually! it is my goal to let everyone experience this phenomenon easily :)

from stylegan2-pytorch.

josephrocca avatar josephrocca commented on May 25, 2024 1

Oh, I've just converted them to jpgs and it seems to be working now!

mogrify -format jpg ./twemoji/assets/72x72/*.png
rm ./twemoji/assets/72x72/*.png

from stylegan2-pytorch.

lucidrains avatar lucidrains commented on May 25, 2024 1

ok, try again! ff09e94

from stylegan2-pytorch.

josephrocca avatar josephrocca commented on May 25, 2024 1

All working fine now! Thanks again for this! :)

from stylegan2-pytorch.

josephrocca avatar josephrocca commented on May 25, 2024

I tried resizing the twemoji images to 256x256 like so:

sudo apt-get install imagemagick
git clone https://github.com/twitter/twemoji.git
mogrify -resize 256x256 ./twemoji/assets/72x72/*.png
stylegan2_pytorch --data ./twemoji/assets/72x72

But that didn't help, although the error message was slightly different:

RuntimeError: Given groups=1, weight of size 16 3 1 1, expected input[3, 4, 128, 128] to have 3 channels, but got 4 channels instead

from stylegan2-pytorch.

josephrocca avatar josephrocca commented on May 25, 2024

@lucidrains Perhaps an error message could be shown to tell people that they can't use png images? I assumed it would be as easy as (something like) this (stylegan2_pytorch.py#L133):

    def __getitem__(self, index):
        path = self.paths[index]
        img = Image.open(path)
        img.convert('RGB')
        img.save('__tmp395739487394.jpg')
        jpg = Image.open('__tmp395739487394.jpg')
        return self.transform(jpg)

But that still results in the same error for some reason (using the mnist_png):

RuntimeError: Given groups=1, weight of size 16 3 1 1, expected input[3, 1, 128, 128] to have 3 channels, but got 1 channels instead

and this on the twemoji dataset:

UserWarning: Palette images with Transparency expressed in bytes should be converted to RGBA images

from stylegan2-pytorch.

lucidrains avatar lucidrains commented on May 25, 2024

@josephrocca I made another patch! upgrade the package!

from stylegan2-pytorch.

josephrocca avatar josephrocca commented on May 25, 2024

Works for the mnist_png code now! Getting this for the twemoji example:

  0%|                                                          | 0/100000 [00:00<?, ?it/s]G: -3314.26 | D: 52.87 | GP: 103.12 | PL: 0.20
  0%|                                              | 15/100000 [00:10<18:33:42,  1.50it/s]Traceback (most recent call last):
  File "/home/user/miniconda/envs/py36/bin/stylegan2_pytorch", line 56, in <module>
    fire.Fire(train_from_folder)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/fire/core.py", line 138, in Fire
    component_trace = _Fire(component, args, parsed_flag_args, context, name)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/fire/core.py", line 471, in _Fire
    target=component.__name__)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/fire/core.py", line 675, in _CallAndUpdateTrace
    component = fn(*varargs, **kwargs)
  File "/home/user/miniconda/envs/py36/bin/stylegan2_pytorch", line 51, in train_from_folder
    model.train()
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/stylegan2_pytorch/stylegan2_pytorch.py", line 459, in train
    image_batch = next(self.loader).cuda()
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/stylegan2_pytorch/stylegan2_pytorch.py", line 75, in cycle
    for i in iterable:
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 345, in __next__
    data = self._next_data()
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 856, in _next_data
    return self._process_data(data)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 881, in _process_data
    data.reraise()
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/torch/_utils.py", line 394, in reraise
    raise self.exc_type(msg)
RuntimeError: Caught RuntimeError in DataLoader worker process 13.
Original Traceback (most recent call last):
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/torch/utils/data/_utils/worker.py", line 178, in _worker_loop
    data = fetcher.fetch(index)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/torch/utils/data/_utils/fetch.py", line 44, in <listcomp>
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/stylegan2_pytorch/stylegan2_pytorch.py", line 140, in __getitem__
    return self.transform(img)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/torchvision/transforms/transforms.py", line 70, in __call__
    img = t(img)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/torchvision/transforms/transforms.py", line 322, in __call__
    return self.lambd(img)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/stylegan2_pytorch/stylegan2_pytorch.py", line 112, in expand_to_rgb
    return tensor.expand(3, -1, -1)
RuntimeError: The expanded size of the tensor (3) must match the existing size (4) at non-singleton dimension 0.  Target sizes: [3, -1, -1].  Tensor sizes: [4, 128, 128]

  0%|                                              | 15/100000 [00:13<24:54:58,  1.11it/s]
Exception in thread Thread-2:
Traceback (most recent call last):
  File "/home/user/miniconda/envs/py36/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/home/user/miniconda/envs/py36/lib/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/torch/utils/data/_utils/pin_memory.py", line 25, in _pin_memory_loop
    r = in_queue.get(timeout=MP_STATUS_CHECK_INTERVAL)
  File "/home/user/miniconda/envs/py36/lib/python3.6/multiprocessing/queues.py", line 113, in get
    return _ForkingPickler.loads(res)
  File "/home/user/miniconda/envs/py36/lib/python3.6/site-packages/torch/multiprocessing/reductions.py", line 294, in rebuild_storage_fd
    fd = df.detach()
  File "/home/user/miniconda/envs/py36/lib/python3.6/multiprocessing/resource_sharer.py", line 57, in detach
    with _resource_sharer.get_connection(self._id) as conn:
  File "/home/user/miniconda/envs/py36/lib/python3.6/multiprocessing/resource_sharer.py", line 87, in get_connection
    c = Client(address, authkey=process.current_process().authkey)
  File "/home/user/miniconda/envs/py36/lib/python3.6/multiprocessing/connection.py", line 493, in Client
    answer_challenge(c, authkey)
  File "/home/user/miniconda/envs/py36/lib/python3.6/multiprocessing/connection.py", line 732, in answer_challenge
    message = connection.recv_bytes(256)         # reject large message
  File "/home/user/miniconda/envs/py36/lib/python3.6/multiprocessing/connection.py", line 216, in recv_bytes
    buf = self._recv_bytes(maxlength)
  File "/home/user/miniconda/envs/py36/lib/python3.6/multiprocessing/connection.py", line 407, in _recv_bytes
    buf = self._recv(4)
  File "/home/user/miniconda/envs/py36/lib/python3.6/multiprocessing/connection.py", line 379, in _recv
    chunk = read(handle, remaining)
ConnectionResetError: [Errno 104] Connection reset by peer

Exact replication:

sudo docker run --gpus all --rm -it anibali/pytorch:cuda-10.1 bash
pip install stylegan2_pytorch
git clone https://github.com/twitter/twemoji.git
stylegan2_pytorch --data ./twemoji/assets/72x72

This is not important at all though (very easy to convert to jpg) - only reporting to help make your package super easy for others to get started with. I'm worried that I'm taking your time away from more important things with these nit picks 😅

from stylegan2-pytorch.

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.