Coder Social home page Coder Social logo

Comments (7)

lucidrains avatar lucidrains commented on August 22, 2024 2

https://github.com/lucidrains/lightweight-gan/releases/tag/0.14.0 ok done with the --greyscale flag

from lightweight-gan.

stefanorosss avatar stefanorosss commented on August 22, 2024 1

You are definitely right! I started with the assumption of wanting to change from RGB and didn't question it later, thanks

from lightweight-gan.

woctezuma avatar woctezuma commented on August 22, 2024

Just a quick comment: wouldn't it have been simpler to edit the logic the other way around? Rather than keeping "transparent" and replacing RGB with grayscale, you could have kept RGB and replaced "transparent" (4 channels) with "grayscale" (1 channel). In this case, all you would have to do is Ctrl+F "transparent" (32 matches) in https://github.com/lucidrains/lightweight-gan/blob/main/lightweight_gan/lightweight_gan.py and change the logic every time.

Here, you have the expand_greyscale class, which risks setting the number of channels back to 3:

class expand_greyscale(object):
def __init__(self, transparent):
self.transparent = transparent
def __call__(self, tensor):
channels = tensor.shape[0]
num_target_channels = 4 if self.transparent else 3
if channels == num_target_channels:
return tensor
alpha = None
if channels == 1:
color = tensor.expand(3, -1, -1)
elif channels == 2:
color = tensor[:1].expand(3, -1, -1)
alpha = tensor[1:]
else:
raise Exception(f'image with invalid number of channels given {channels}')
if not exists(alpha) and self.transparent:
alpha = torch.ones(1, *tensor.shape[1:], device=tensor.device)
return color if not self.transparent else torch.cat((color, alpha))

which is then called at the end here by transforms.Lambda(expand_greyscale(transparent)):

convert_image_fn = partial(convert_image_to, 'RGBA' if transparent else 'RGB')
num_channels = 3 if not transparent else 4
self.transform = transforms.Compose([
transforms.Lambda(convert_image_fn),
transforms.Lambda(partial(resize_to_minimum_size, image_size)),
transforms.Resize(image_size),
RandomApply(aug_prob, transforms.RandomResizedCrop(image_size, scale=(0.5, 1.0), ratio=(0.98, 1.02)), transforms.CenterCrop(image_size)),
transforms.ToTensor(),
transforms.Lambda(expand_greyscale(transparent))
])

Apart from that, there are the changes below which you have already mentioned:

from lightweight-gan.

bogdan-ivan avatar bogdan-ivan commented on August 22, 2024

This would be great to be added as an option. @lucidrains

from lightweight-gan.

lucidrains avatar lucidrains commented on August 22, 2024

@bogdan-ivan sure, i'll add it! what is the corresponding enum string in pillow for greyscale? (like RGBA is for transparent)

from lightweight-gan.

woctezuma avatar woctezuma commented on August 22, 2024

@bogdan-ivan sure, i'll add it! what is the corresponding enum string in pillow for greyscale? (like RGBA is for transparent)

The last time I checked, it was L.

https://pillow.readthedocs.io/en/stable/handbook/concepts.html#modes

from lightweight-gan.

Dok11 avatar Dok11 commented on August 22, 2024

@lucidrains I think about --num-channels flag. For example to generation textures which contain several maps (albedo, roughness, specular, normal map). How do you think does possible modify code to work with them? And will it be too hard or easy?

from lightweight-gan.

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.