mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
Add regression test (#136)
* Add regression test * fix regression test with full_precision
This commit is contained in:
parent
8ca4d6542d
commit
d524e5797d
32
.dev_scripts/diff_images.py
Normal file
32
.dev_scripts/diff_images.py
Normal file
@ -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)
|
Binary file not shown.
After Width: | Height: | Size: 416 KiB |
1
.dev_scripts/sample_command.txt
Normal file
1
.dev_scripts/sample_command.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
"a photograph of an astronaut riding a horse" -s50 -S42
|
20
.dev_scripts/test_regression_txt2img_dream_v1_4.sh
Normal file
20
.dev_scripts/test_regression_txt2img_dream_v1_4.sh
Normal file
@ -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}
|
23
.dev_scripts/test_regression_txt2img_v1_4.sh
Normal file
23
.dev_scripts/test_regression_txt2img_v1_4.sh
Normal file
@ -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}
|
Loading…
Reference in New Issue
Block a user