Skip to content

Commit

Permalink
feat(doc): update inference models and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
royale authored and beniz committed Sep 1, 2023
1 parent 98cef11 commit 3c43a7b
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 8 deletions.
Binary file modified docs/source/_static/gan_glasses2noglasses_output.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/_static/noglasses2glasses_ddpm_mask.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 8 additions & 7 deletions docs/source/inference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ Download a pretrained model:

.. code:: bash
wget https://joligen.com/models/glasses2noglasses.zip
unzip glasses2noglasses.zip
wget https://joligen.com/models/joligen_model_gan_glasses2noglasses.zip
unzip joligen_model_gan_glasses2noglasses.zip
mkdir checkpoints
mv glasses2noglasses/ ./checkpoints/
rm glasses2noglasses.zip
rm joligen_model_gan_glasses2noglasses.zip
Run the inference script
========================
Expand All @@ -57,6 +57,7 @@ The output file is the ``target.jpg`` image in the current directory:
:class: borderless

- - .. image:: _static/gan_glasses2noglasses_orig_image.jpg
:width: 128
- .. image:: _static/gan_glasses2noglasses_output.jpg

- - original image given as input to the model
Expand Down Expand Up @@ -89,11 +90,11 @@ Download a pretrained model:

.. code:: bash
wget https://joligen.com/models/noglasses2glasses.zip
unzip noglasses2glasses.zip
wget https://joligen.com/models/joligen_model_ddpm_noglasses2glasses.zip
unzip joligen_model_ddpm_noglasses2glasses.zip
mkdir checkpoints
mv noglasses2glasses/ ./checkpoints/
rm noglasses2glasses.zip
rm joligen_model_ddpm_noglasses2glasses.zip
Run the inference script
========================
Expand All @@ -102,7 +103,7 @@ Run the inference script
mkdir noglasses2glasses_inference_output
cd scripts/
python3 gen_single_image_diffusion.py --model-in-file ../checkpoints/noglasses2glasses/latest_net_G_A.pth --img-in ../datasets/noglasses2glasses_ffhq/trainA/img/00001.jpg --mask-in ../datasets/noglasses2glasses_ffhq/trainA/bbox/00001.jpg --dir-out ../noglasses2glasses_inference_output --img-width 128 --img-height 128
python3 gen_single_image_diffusion.py --model-in-file ../checkpoints/noglasses2glasses/latest_net_G_A.pth --img-in ../datasets/noglasses2glasses_ffhq/trainA/img/00002.jpg --mask-in ../datasets/noglasses2glasses_ffhq/trainA/bbox/00002.jpg --dir-out ../noglasses2glasses_inference_output --img-width 128 --img-height 128
The output files will be in the ``noglasses2glasses_inference_output``
folder, with:
Expand Down
2 changes: 1 addition & 1 deletion examples/example_ddpm_noglasses2glasses.json
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@
"checkpoints_dir": "./checkpoints/",
"dataroot": "noglasses2glasses_ffhq",
"ddp_port": "12355",
"gpu_ids": "1",
"gpu_ids": "0",
"model_type": "palette",
"name": "noglasses2glasses",
"phase": "train",
Expand Down
9 changes: 9 additions & 0 deletions scripts/gen_single_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ def load_model(modelpath, model_in_file, cpu, gpuid):

parser.add_argument("--img-in", help="image to transform", required=True)
parser.add_argument("--img-out", help="transformed image", required=True)
parser.add_argument(
"--img-width", type=int, help="image width, defaults to model crop size"
)
parser.add_argument(
"--img-height", type=int, help="image height, defaults to model crop size"
)
parser.add_argument("--cpu", action="store_true", help="whether to use CPU")
parser.add_argument("--gpuid", type=int, default=0, help="which GPU to use")
args = parser.parse_args()
Expand All @@ -65,8 +71,11 @@ def load_model(modelpath, model_in_file, cpu, gpuid):
)

# reading image
img_width = args.img_width if args.img_width is not None else opt.data_crop_size
img_height = args.img_height if args.img_height is not None else opt.data_crop_size
img = cv2.imread(args.img_in)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img = cv2.resize(img, (img_width, img_height), interpolation=cv2.INTER_CUBIC)

# preprocessing
tranlist = [
Expand Down

0 comments on commit 3c43a7b

Please sign in to comment.