Add a test image for stable diffusion (#20780)

This commit is contained in:
Yi Zhang 2024-05-23 23:50:23 +08:00 committed by GitHub
parent 2c39d0c502
commit fa8670fe5b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 31 additions and 4 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 477 KiB

View file

@ -14,6 +14,7 @@ def arg_parser():
parser.add_argument("--image1", type=str, help="Path to image 1")
parser.add_argument("--image2", type=str, help="Path to image 2")
parser.add_argument("--cache_dir", type=str, help="Path to model cache directory")
parser.add_argument("--negative", action="store_true", help="match the unexpected image, for testing purpose")
args = parser.parse_args()
return args
@ -62,11 +63,16 @@ def main():
cache_dir = args.cache_dir
score = round(generate_score(image1, image2, cache_dir), 2)
print("similarity Score: ", {score})
if score < 97:
print(f"{image1} and {image2} are different")
raise SystemExit(1)
if args.negative:
if score > 97:
print("Why generated this incorrect image")
raise SystemExit(1)
else:
print(f"{image1} and {image2} are same")
if score < 97:
print(f"{image1} and {image2} are different")
raise SystemExit(1)
else:
print(f"{image1} and {image2} are same")
if __name__ == "__main__":

View file

@ -244,6 +244,27 @@ stages:
path: $(CLIP_MODEL_CACHE)
displayName: Cache clip model
- script: |
docker run --rm --gpus all -v $PWD:/workspace \
-v $(CLIP_MODEL_CACHE):/model_cache:rw \
nvcr.io/nvidia/pytorch:22.11-py3 \
bash -c '
set -ex; \
python3 --version; \
python3 -m pip install --upgrade pip; \
pushd /workspace/onnxruntime/python/tools/transformers/models/stable_diffusion/; \
image2=$(find $(pwd) -name "astronaut_riding_a_h*.png") ; \
pushd test; \
python3 -m pip install -r requirements.txt; \
echo check demo_txt2image.py generate image; \
python3 -u check_image.py --image1 astronaut_riding_error.png --image2 $image2 --cache_dir /model_cache --negative; \
popd ; \
popd ; \
'
displayName: 'Check if the generated image is wierd'
workingDirectory: $(Build.SourcesDirectory)
continueOnError: true
- script: |
docker run --rm --gpus all -v $PWD:/workspace \
-v $(CLIP_MODEL_CACHE):/model_cache:rw \