yuval-alaluf / SAM

Official Implementation for "Only a Matter of Style: Age Transformation Using a Style-Based Regression Model" (SIGGRAPH 2021) https://arxiv.org/abs/2102.02754
https://yuval-alaluf.github.io/SAM/
MIT License
632 stars 151 forks source link

I want to test the trained model of SAM directly in my machine. #7

Closed MetiCodePrivateLimited closed 3 years ago

MetiCodePrivateLimited commented 3 years ago

After successfully configuration, how can I run trained model of SAM in my machine. Could you elaborate all steps in detail?

yuval-alaluf commented 3 years ago

What machine are you running on? All of our work was done on Linux. If you plan working on windows I can help point you in the right direction, but I have never tried running on Windows myself.

MetiCodePrivateLimited commented 3 years ago

Sorry for could not elaborate my issue right. I want to run your already trained model to transform Age Face effects. How can I run those scripts?

yuval-alaluf commented 3 years ago

The README provides a pretty detailed step by step guide for how to run inference on a trained model. Is there a particular part that is not clear?

MetiCodePrivateLimited commented 3 years ago

I am trying to execute following command after getting git clone of SAM project in my linux based system, cd /usr/local/SAM

and under SAM, following is the code: python scripts/reference_guided_inference.py \ --exp_dir=/path/to/experiment \ --checkpoint_path=experiment/checkpoints/best_model.pt \ --data_path=/path/to/test_data \ --test_batch_size=4 \ --test_workers=4 \ --ref_images_paths_file=/path/to/ref_list.txt \ --latent_mask=8,9 \ --target_age=50,60,70,80

Do I need to self create folders i.e. "path/to/experiment", "path/to/test_data", "path/to/ref"? Also, from where would I get "best_model.pt"?

yuval-alaluf commented 3 years ago

Are you sure that scripts/reference_guided_inference.py is the script you want to run? Are you trying to simply change a given image's age? If so, you should use the regular inference script.

In any case, yes you need to define the exp_dir which is where the outputs will be saved. The data path is the path to the directory holding the images you want to run on.

I provided the link for downloading the pretrained model in the README. You should download the model, save it to whatever path you want, and place the chosen path to checkpoint_path.

MetiCodePrivateLimited commented 3 years ago

What are the functionality of following parameters that are used in commands. 1) --test_batch_size=4 2) --test_workers=4 3) --latent_mask=8,9

yuval-alaluf commented 3 years ago

The batch size is the number of images you pass through the network together and the number of workers is a parameter used by the dataloader (you don't need to worry about this one too much). The latent mask is used to perform style mixing. Here, we specify that we want to perform style mixing with a reference image on layers 8 and 9 of StyleGAN. Again, just make sure you're running the right script for inference. More details on the functionality of each script is provided in the README.

MetiCodePrivateLimited commented 3 years ago

on the execution of following code, I got an error --****-- python3 scripts/inference.py \ --exp_dir= /to/experiment \ --checkpoint_path= /trainedmodels/sam_ffhq_aging.pt \ --data_path= /to/test_data \ --test_batch_size=4 \ --test_workers=4 \ --couple_outputs \ --target_age=0,10,20,30,40,50,60,70,80

--****--

Traceback (most recent call last): File "scripts/inference.py", line 19, in from models.psp import pSp File "./models/psp.py", line 12, in from models.encoders import psp_encoders File "./models/encoders/psp_encoders.py", line 8, in from models.stylegan2.model import EqualLinear File "./models/stylegan2/model.py", line 7, in from models.stylegan2.op import FusedLeakyReLU, fused_leaky_relu, upfirdn2d File "./models/stylegan2/op/init.py", line 1, in from .fused_act import FusedLeakyReLU, fused_leaky_relu File "./models/stylegan2/op/fused_act.py", line 13, in os.path.join(module_path, 'fused_bias_act_kernel.cu'), File "/root/anaconda3/envs/sam_env/lib/python3.6/site-packages/torch/utils/cpp_extension.py", line 974, in load keep_intermediates=keep_intermediates) File "/root/anaconda3/envs/sam_env/lib/python3.6/site-packages/torch/utils/cpp_extension.py", line 1179, in _jit_compile with_cuda=with_cuda) File "/root/anaconda3/envs/sam_env/lib/python3.6/site-packages/torch/utils/cpp_extension.py", line 1251, in _write_ninja_file_and_build_library check_compiler_abi_compatibility(compiler) File "/root/anaconda3/envs/sam_env/lib/python3.6/site-packages/torch/utils/cpp_extension.py", line 248, in check_compiler_abi_compatibility if not check_compiler_ok_for_platform(compiler): File "/root/anaconda3/envs/sam_env/lib/python3.6/site-packages/torch/utils/cpp_extension.py", line 208, in check_compiler_ok_for_platform which = subprocess.check_output(['which', compiler], stderr=subprocess.STDOUT) File "/root/anaconda3/envs/sam_env/lib/python3.6/subprocess.py", line 336, in check_output **kwargs).stdout File "/root/anaconda3/envs/sam_env/lib/python3.6/subprocess.py", line 418, in run output=stdout, stderr=stderr) subprocess.CalledProcessError: Command '['which', 'c++']' returned non-zero exit status 1.

MetiCodePrivateLimited commented 3 years ago

I solved it myself