Skip to content

Commit d524e57

Browse files
authored
Add regression test (#136)
* Add regression test * fix regression test with full_precision
1 parent 8ca4d65 commit d524e57

File tree

5 files changed

+76
-0
lines changed

5 files changed

+76
-0
lines changed

.dev_scripts/diff_images.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import argparse
2+
3+
import numpy as np
4+
from PIL import Image
5+
6+
7+
def read_image_int16(image_path):
8+
image = Image.open(image_path)
9+
return np.array(image).astype(np.int16)
10+
11+
12+
def calc_images_mean_L1(image1_path, image2_path):
13+
image1 = read_image_int16(image1_path)
14+
image2 = read_image_int16(image2_path)
15+
assert image1.shape == image2.shape
16+
17+
mean_L1 = np.abs(image1 - image2).mean()
18+
return mean_L1
19+
20+
21+
def parse_args():
22+
parser = argparse.ArgumentParser()
23+
parser.add_argument('image1_path')
24+
parser.add_argument('image2_path')
25+
args = parser.parse_args()
26+
return args
27+
28+
29+
if __name__ == '__main__':
30+
args = parse_args()
31+
mean_L1 = calc_images_mean_L1(args.image1_path, args.image2_path)
32+
print(mean_L1)
416 KB
Loading

.dev_scripts/sample_command.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"a photograph of an astronaut riding a horse" -s50 -S42
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# generate an image
2+
PROMPT_FILE=".dev_scripts/sample_command.txt"
3+
OUT_DIR="outputs/img-samples/test_regression_txt2img_v1_4"
4+
SAMPLES_DIR=${OUT_DIR}
5+
python scripts/dream.py \
6+
--from_file ${PROMPT_FILE} \
7+
--outdir ${OUT_DIR} \
8+
--sampler plms \
9+
--full_precision
10+
11+
# original output by CompVis/stable-diffusion
12+
IMAGE1=".dev_scripts/images/v1_4_astronaut_rides_horse_plms_step50_seed42.png"
13+
# new output
14+
IMAGE2=`ls -A ${SAMPLES_DIR}/*.png | sort | tail -n 1`
15+
16+
echo ""
17+
echo "comparing the following two images"
18+
echo "IMAGE1: ${IMAGE1}"
19+
echo "IMAGE2: ${IMAGE2}"
20+
python .dev_scripts/diff_images.py ${IMAGE1} ${IMAGE2}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# generate an image
2+
PROMPT="a photograph of an astronaut riding a horse"
3+
OUT_DIR="outputs/txt2img-samples/test_regression_txt2img_v1_4"
4+
SAMPLES_DIR="outputs/txt2img-samples/test_regression_txt2img_v1_4/samples"
5+
python scripts/orig_scripts/txt2img.py \
6+
--prompt "${PROMPT}" \
7+
--outdir ${OUT_DIR} \
8+
--plms \
9+
--ddim_steps 50 \
10+
--n_samples 1 \
11+
--n_iter 1 \
12+
--seed 42
13+
14+
# original output by CompVis/stable-diffusion
15+
IMAGE1=".dev_scripts/images/v1_4_astronaut_rides_horse_plms_step50_seed42.png"
16+
# new output
17+
IMAGE2=`ls -A ${SAMPLES_DIR}/*.png | sort | tail -n 1`
18+
19+
echo ""
20+
echo "comparing the following two images"
21+
echo "IMAGE1: ${IMAGE1}"
22+
echo "IMAGE2: ${IMAGE2}"
23+
python .dev_scripts/diff_images.py ${IMAGE1} ${IMAGE2}

0 commit comments

Comments
 (0)