Skip to content

Commit 0a57226

Browse files
committed
Use TestImages to avoid flaky download
We can guarantee these test images will always be available, which is not the case for the current sample image.
1 parent 4dfdbd8 commit 0a57226

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

test/Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c"
44
Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0"
55
ReTestItems = "817f1d60-ba6b-4fd5-9520-3cf149f6a823"
66
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
7+
TestImages = "5e47fb64-e119-507b-a336-dd2b206d9990"
78
TestItemRunner = "f8b46487-2199-4994-9208-9a1283c18c0a"
89
cuDNN = "02a925ec-e4fe-4b08-9a7e-0d78e3d38ccd"
910

@@ -13,5 +14,6 @@ Flux = "0.13.16, 0.14"
1314
Images = "0.26"
1415
ReTestItems = "1"
1516
Test = "1"
17+
TestImages = "1.8"
1618
TestItemRunner = "0.2"
1719
cuDNN = "1"

test/model_tests.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@testsetup module TestModels
2-
using Metalhead, Images
2+
using Metalhead, Images, TestImages
33
using Flux: gradient, gpu
44

55
export PRETRAINED_MODELS,
@@ -62,8 +62,7 @@ function normalize_imagenet(data)
6262
end
6363

6464
# test image
65-
const TEST_PATH = download("https://cdn.pixabay.com/photo/2015/05/07/11/02/guitar-756326_960_720.jpg")
66-
const TEST_IMG = imresize(Images.load(TEST_PATH), (224, 224))
65+
const TEST_IMG = imresize(testimage("monarch_color_256"), (224, 224))
6766
# CHW -> WHC
6867
const TEST_X = let img_array = convert(Array{Float32}, channelview(TEST_IMG))
6968
permutedims(img_array, (3, 2, 1)) |> normalize_imagenet |> gpu
@@ -75,7 +74,7 @@ const TEST_LBLS = readlines(download("https://raw.githubusercontent.com/pytorch/
7574
function acctest(model)
7675
ypred = gpu(model)(TEST_X) |> vec
7776
top5 = TEST_LBLS[sortperm(ypred; rev = true)]
78-
return "acoustic guitar" in top5
77+
return "monarch" in top5
7978
end
8079

8180
const x_224 = rand(Float32, 224, 224, 3, 1) |> gpu

0 commit comments

Comments
 (0)