-
Notifications
You must be signed in to change notification settings - Fork 2
/
efficientnet_test.py
54 lines (40 loc) · 1.46 KB
/
efficientnet_test.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import numpy as np
from skimage.io import imread
import matplotlib.pyplot as plt
from tensorflow.keras.applications.imagenet_utils import decode_predictions as decode_efnet
from efficientnet.tfkeras import EfficientNetB0
from efficientnet.tfkeras import center_crop_and_resize
from efficientnet.tfkeras import preprocess_input as preprocess_efficientnet
# ResNetV2
from tensorflow.keras.applications.resnet_v2 import decode_predictions as decode_resnet
from tensorflow.keras.applications.resnet_v2 import preprocess_input as preprocess_resnet
from tensorflow.keras.applications import ResNet50V2
def load_data():
image = imread("./samples/2021-05-02_17;54;46/img_191.png")
plt.figure(figsize=(10, 10))
plt.imshow(image)
plt.show()
return image
def efficientnet_inference(image):
model = EfficientNetB0(weights='imagenet')
image_size = model.input_shape[1]
print(image_size)
x = center_crop_and_resize(image, image_size=image_size)
x = preprocess_efficientnet(x)
x = np.expand_dims(x, 0)
y = model.predict(x)
print(decode_efnet(y))
def resnet_inference(image):
model = ResNet50V2(weights='imagenet')
image_size = model.input_shape[1]
print(image_size)
x = np.resize(image,(224,224,3))
x = preprocess_resnet(x)
x = np.expand_dims(x, 0)
y = model.predict(x)
print(decode_resnet(y))
image = load_data()
print("efficientnet")
efficientnet_inference(image)
print("resnet")
resnet_inference(image)