-
Notifications
You must be signed in to change notification settings - Fork 0
/
id_image.py
39 lines (30 loc) · 1.22 KB
/
id_image.py
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
38
39
import numpy as np
from skimage.transform import resize
import rawpy
from keras.models import Sequential
from keras.preprocessing import image
from keras.applications.resnet50 import ResNet50
from keras.applications.resnet50 import preprocess_input
from keras.applications.imagenet_utils import decode_predictions
from keras.layers.experimental.preprocessing import CenterCrop
from keras.layers.experimental.preprocessing import Rescaling
import matplotlib.pyplot as plt
from pathlib import Path
resnet = ResNet50(weights='imagenet')
def id_image(path):
print(".. " + path)
cropper = CenterCrop(height=2000, width=2000)
if not Path(path).exists():
return []
if str(path).lower().endswith("nef") or str(path).lower().endswith("orf"): #
with rawpy.imread(path) as raw:
rgb = raw.postprocess()
else:
rgb = image.img_to_array(image.load_img(path))
small = rgb
small = resize(small,(224,224), preserve_range = True)
small = np.expand_dims(small, axis = 0)
small = preprocess_input(small)
preds = resnet.predict(small)
print('Predicted:', decode_predictions(preds, top=3)[0])
return list(map(lambda a : a[1] ,decode_predictions(preds, top=3)[0]))