-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.jl
37 lines (27 loc) · 918 Bytes
/
demo.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
## %%
using Metalhead
using Images
using Flux
using Flux: onecold
using DataAugmentation
model = ResNet(101, pretrain=true);
##%%
img = Images.load("imgs/ILSVRC2012_val_00035585.JPEG")
img_data = apply(augmentations, Image(img)) |> itemdata
# img = Images.load("imgs/dog.jpg")
# img_data = apply(augmentations, Image(img)) |> itemdata
#%%
predictions = model(Flux.unsqueeze(img_data, 4))
predict = softmax(predictions)
println(maximum(predict))
print(onecold(predictions, labels))
#%%
DATA_MEAN = (0.485, 0.456, 0.406)
DATA_STD = (0.229, 0.224, 0.225)
augmentations = CenterCrop((224, 224)) |>
ImageToTensor() |>
Normalize(DATA_MEAN, DATA_STD)
data = apply(augmentations, Image(img)) |> itemdata
# ImageNet labels
labels = readlines(download("https://raw.githubusercontent.com/pytorch/hub/master/imagenet_classes.txt"))
println(onecold(model(Flux.unsqueeze(data, 4)), labels))