diff --git a/.dev_scripts/diff_images.py b/.dev_scripts/diff_images.py new file mode 100644 index 0000000000..e21cae214e --- /dev/null +++ b/.dev_scripts/diff_images.py @@ -0,0 +1,32 @@ +import argparse + +import numpy as np +from PIL import Image + + +def read_image_int16(image_path): + image = Image.open(image_path) + return np.array(image).astype(np.int16) + + +def calc_images_mean_L1(image1_path, image2_path): + image1 = read_image_int16(image1_path) + image2 = read_image_int16(image2_path) + assert image1.shape == image2.shape + + mean_L1 = np.abs(image1 - image2).mean() + return mean_L1 + + +def parse_args(): + parser = argparse.ArgumentParser() + parser.add_argument('image1_path') + parser.add_argument('image2_path') + args = parser.parse_args() + return args + + +if __name__ == '__main__': + args = parse_args() + mean_L1 = calc_images_mean_L1(args.image1_path, args.image2_path) + print(mean_L1) diff --git a/.dev_scripts/images/v1_4_astronaut_rides_horse_plms_step50_seed42.png b/.dev_scripts/images/v1_4_astronaut_rides_horse_plms_step50_seed42.png new file mode 100644 index 0000000000..c91c714c02 Binary files /dev/null and b/.dev_scripts/images/v1_4_astronaut_rides_horse_plms_step50_seed42.png differ diff --git a/.dev_scripts/sample_command.txt b/.dev_scripts/sample_command.txt new file mode 100644 index 0000000000..cd1530e8c1 --- /dev/null +++ b/.dev_scripts/sample_command.txt @@ -0,0 +1 @@ +"a photograph of an astronaut riding a horse" -s50 -S42 diff --git a/.dev_scripts/test_regression_txt2img_dream_v1_4.sh b/.dev_scripts/test_regression_txt2img_dream_v1_4.sh new file mode 100644 index 0000000000..11cbf8f14b --- /dev/null +++ b/.dev_scripts/test_regression_txt2img_dream_v1_4.sh @@ -0,0 +1,20 @@ +# generate an image +PROMPT_FILE=".dev_scripts/sample_command.txt" +OUT_DIR="outputs/img-samples/test_regression_txt2img_v1_4" +SAMPLES_DIR=${OUT_DIR} +python scripts/dream.py \ + --from_file ${PROMPT_FILE} \ + --outdir ${OUT_DIR} \ + --sampler plms \ + --full_precision + +# original output by CompVis/stable-diffusion +IMAGE1=".dev_scripts/images/v1_4_astronaut_rides_horse_plms_step50_seed42.png" +# new output +IMAGE2=`ls -A ${SAMPLES_DIR}/*.png | sort | tail -n 1` + +echo "" +echo "comparing the following two images" +echo "IMAGE1: ${IMAGE1}" +echo "IMAGE2: ${IMAGE2}" +python .dev_scripts/diff_images.py ${IMAGE1} ${IMAGE2} diff --git a/.dev_scripts/test_regression_txt2img_v1_4.sh b/.dev_scripts/test_regression_txt2img_v1_4.sh new file mode 100644 index 0000000000..e7d1b8c333 --- /dev/null +++ b/.dev_scripts/test_regression_txt2img_v1_4.sh @@ -0,0 +1,23 @@ +# generate an image +PROMPT="a photograph of an astronaut riding a horse" +OUT_DIR="outputs/txt2img-samples/test_regression_txt2img_v1_4" +SAMPLES_DIR="outputs/txt2img-samples/test_regression_txt2img_v1_4/samples" +python scripts/orig_scripts/txt2img.py \ + --prompt "${PROMPT}" \ + --outdir ${OUT_DIR} \ + --plms \ + --ddim_steps 50 \ + --n_samples 1 \ + --n_iter 1 \ + --seed 42 + +# original output by CompVis/stable-diffusion +IMAGE1=".dev_scripts/images/v1_4_astronaut_rides_horse_plms_step50_seed42.png" +# new output +IMAGE2=`ls -A ${SAMPLES_DIR}/*.png | sort | tail -n 1` + +echo "" +echo "comparing the following two images" +echo "IMAGE1: ${IMAGE1}" +echo "IMAGE2: ${IMAGE2}" +python .dev_scripts/diff_images.py ${IMAGE1} ${IMAGE2}