GithubHelp home page GithubHelp logo

hasnainraz / fast-aginggan Goto Github PK

View Code? Open in Web Editor NEW
207.0 7.0 47.0 10.15 MB

A deep learning model to age faces in the wild, currently runs at 60+ fps on GPUs

Python 100.00%
gan generative-adversarial-network face-aging cycle-gan pytorch pytorch-lightning neural-network tensorboard cnn realtime-face-aging

fast-aginggan's Introduction

Fast-AgingGAN

This repository holds code for a face aging deep learning model. It is based on the CycleGAN, where we translate young faces to old and vice versa.

Samples

Top row is input image, bottom row is aged output from the GAN. Sample Second-Sample

Timing

The model executes at 66fps on a GTX1080 with an image size of 512x512. Because of the way it is trained, a face detection pipeline is not needed. As long as the image of spatial dims 512x512 contains a face of size 256x256, this will work fine.

Demo

To try out the pretrained model on your images, use the following command:

python infer.py --image_dir 'path/to/your/image/directory'

Training

To train your own model on CACD or UTK faces datasets, you can use the provided preprocessing scripts in the preprocessing directory to prepare the dataset. If you are going to use CACD, use the following command:

python preprocessing/preprocess_cacd.py --image_dir '/path/to/cacd/images' --metadata '/path/to/the/cacd/metadata/file' --output_dir 'path/to/save/processed/data'

If using UTK faces, use the following:

python preprocessing/preprocess_utk.py --data_dir '/path/to/cacd/images' --output_dir 'path/to/save/processed/data'

Once the dataset is processed, you should go into configs/aging_gan.yaml and modify the paths to point to the processed dataset you just created. Change any other hyperparameters if you wish, then run training with:

python main.py

Tensorboard

While training is running, you can observe the losses and the gan generated images in tensorboard, just point it to the 'lightning_logs' directory like so:

tensorboard --logdir=lightning_logs --bind_all

fast-aginggan's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

fast-aginggan's Issues

save the final model?

Hi! May I know that do we have to add codes to save the final .pth file to a file path?

Poor Result

On training the model on UTKFaces to compare the result with the pretrained model for 100 and 200 epochs, I got a loss of about 1.67 for both epochs. While using the trained weights (see model.load_state_dict(ckpt, strict=False), i have to set strict to false if not, i get error when loading it.
I am getting gray color image when I infer any image with the trained model and I don't know why. Pls, where do you think my problems are in the model?

requirements

Hey can you create a file with all the requirements?

The result is bad

hi, i just run the infer.py but the results is bad, is it any .pth updated?

This issue when I train main.py

File "/home/cv-lab/FA/Fast-AgingGAN-master/gan_module.py", line 124, in configure_optimizers
lr=self.hparams['lr'],
KeyError: 'lr'

Age as parameter

Is there any way to tweak the config to try and get age as a parameter? For example, if I wanted someone 20-30ish, 30-40ish, 40-50, etc. The output looks great so far, but would love to be able to have more fine grained control of the aging appearance

pytorch_lightning.utilities.debugging.MisconfigurationException:

pytorch_lightning.utilities.debugging.MisconfigurationException:
You requested GPUs: [0]
But your machine only has: []
hello, why it can not scan my gpu, i already have a gpu named [0], however it always have such error. do you have same error before? thanks a lot

I need your help me.

You use a modelling part.
An error has occurred.
Help me.
Did I do something wrong?

It is said that the route is unknown.

image

Config file

Is there anything in the config file that will help tweak the results generated from infer?

Issues to run code in colab

Im trying to run your infer.py code on colab. I did so by copying line by line and pasting it on my notebook. I had to only change my file paths as I was working on colab. At first I struggled because it was giving me this error.

RuntimeError Traceback (most recent call last)
in ()
18 aged_face = (aged_face.squeeze().permute(1, 2, 0) + 1.0) / 2.0
19 ax[0, i].imshow((img.squeeze().permute(1, 2, 0) + 1.0) / 2.0)
---> 20 ax[1, i].imshow(aged_face)
21 plt.show()

6 frames
/usr/local/lib/python3.7/dist-packages/matplotlib/init.py in inner(ax, data, *args, **kwargs)
1563 def inner(ax, *args, data=None, **kwargs):
1564 if data is None:
-> 1565 return func(ax, *map(sanitize_sequence, args), **kwargs)
1566
1567 bound = new_sig.bind(ax, *args, **kwargs)

/usr/local/lib/python3.7/dist-packages/matplotlib/cbook/deprecation.py in wrapper(*args, **kwargs)
356 f"%(removal)s. If any parameter follows {name!r}, they "
357 f"should be pass as keyword, not positionally.")
--> 358 return func(*args, **kwargs)
359
360 return wrapper

/usr/local/lib/python3.7/dist-packages/matplotlib/cbook/deprecation.py in wrapper(*args, **kwargs)
356 f"%(removal)s. If any parameter follows {name!r}, they "
357 f"should be pass as keyword, not positionally.")
--> 358 return func(*args, **kwargs)
359
360 return wrapper

/usr/local/lib/python3.7/dist-packages/matplotlib/axes/_axes.py in imshow(self, X, cmap, norm, aspect, interpolation, alpha, vmin, vmax, origin, extent, shape, filternorm, filterrad, imlim, resample, url, **kwargs)
5624 resample=resample, **kwargs)
5625
-> 5626 im.set_data(X)
5627 im.set_alpha(alpha)
5628 if im.get_clip_path() is None:

/usr/local/lib/python3.7/dist-packages/matplotlib/image.py in set_data(self, A)
687 if isinstance(A, Image.Image):
688 A = pil_to_array(A) # Needed e.g. to apply png palette.
--> 689 self._A = cbook.safe_masked_invalid(A, copy=True)
690
691 if (self._A.dtype != np.uint8 and

/usr/local/lib/python3.7/dist-packages/matplotlib/cbook/init.py in safe_masked_invalid(x, copy)
704
705 def safe_masked_invalid(x, copy=False):
--> 706 x = np.array(x, subok=True, copy=copy)
707 if not x.dtype.isnative:
708 # Note that the argument to byteswap is 'inplace',

/usr/local/lib/python3.7/dist-packages/torch/tensor.py in array(self, dtype)
619 return handle_torch_function(Tensor.array, (self,), self, dtype=dtype)
620 if dtype is None:
--> 621 return self.numpy()
622 else:
623 return self.numpy().astype(dtype, copy=False)

RuntimeError: Can't call numpy() on Tensor that requires grad. Use tensor.detach().numpy() instead.

I then tried to change the lines as follows:
aged_face = (aged_face.squeeze().permute(1, 2, 0).detach().numpy() + 1.0) / 2.0
ax[0, i].imshow((img.squeeze().permute(1, 2, 0).detach().numpy() + 1.0) / 2.0)

but after doing, i was able to run the line but no output came from it.
So if possible, can you give me a full detailed guide on how do I run your infer.py on colab?
I would really really appreciate the help.
Your response would be acknowleged.

Training command

The training command mentioned in README.md has an issue.
python preprocessing/preprocessing_utk.py --data_dir '/path/to/cacd/images' --output_dir 'path/to/save/processed/data'
Has to be preprocess_utk.py. The file is misnamed.

celebA dataset smile issue

Hi!

I tried to train on the celeb A dataset to make photo go from non-smile to smile and it didn't work.
Do you have any advice?

thank you

too many indices for array

Hello
When I execute the infer.py script, I have this message in return

File "/net/raid3/DEEP/GITHUB/FastAging/infer.py", line 55, in main
ax[0, i].imshow(img)
IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed

How can I fix it please?
Thanks!

Attribute Error

I am attempting to train it from scratch per the instructions and have everything pre-processed and ready, but when I launch main.py I get this. Any ideas?

(fast) ubuntu@chris03:/mnt/workspace/Fast-AgingGAN$ python main.py
{'domainA_dir': 'dataoutput/trainA', 'domainB_dir': 'dataoutput/trainB', 'ngf': 32, 'ndf': 32, 'n_blocks': 9, 'adv_weight': 2, 'cycle_weight': 10, 'identity_weight': 7, 'lr': 0.0001, 'weight_decay': 0.0001, 'img_size': 256, 'batch_size': 3, 'num_workers': 4, 'epochs': 100, 'gpus': [1]}
Traceback (most recent call last):
File "main.py", line 23, in
main()
File "main.py", line 17, in main
model = AgingGAN(config)
File "/mnt/workspace/Fast-AgingGAN/gan_module.py", line 18, in init
self.hparams = hparams
File "/mnt/workspace/Fast-AgingGAN/fast/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1225, in setattr
object.setattr(self, name, value)
AttributeError: can't set attribute

IndexError in infer.py

File "infer.py", line 39, in main

ax[0, i].imshow((img.squeeze().permute(1, 2, 0).numpy() + 1.0) / 2.0)

IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed

Hello, thanks for making this! I was trying to test it out with one image and am running into this error? Do you know why this may be happening?

Running on rgba

Is it possible to run this on png images with rgba values?

No pth file is save after done training model

Hi, i have done training the model, but i didnt saw any pth file in my checkpoint, i only can saw ckpt file.

just want to how to generate it like your pretrained model state_dict.pth once done training

Other transformations

Hey!

Thanks for sharing.
Can it be trained to make the person look younger instead of older?
Can it also be trained for other transformations like make person smile? or remove/add beard/mustache etc?

thanks

old2young

Thanks for sharing
Would you like to share the old2young?
For learning only

about age

Hello, I'm working on your project. I have a simple test and found that the output is not different from the original image. Is there any way to make the results older?

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.