-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtester.py
More file actions
54 lines (42 loc) · 1.42 KB
/
tester.py
File metadata and controls
54 lines (42 loc) · 1.42 KB
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
# -*- coding: utf-8 -*-
"""Tester.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1PCPVQB72jy4biMy9D-d6kXdAUaSF1Fvx
"""
import tensorflow as tf
from tensorflow.keras.preprocessing import image
import numpy as np
# Mount Google Drive
from google.colab import drive
drive.mount('/content/drive')
# Load the saved model
model = tf.keras.models.load_model('/content/drive/MyDrive/detector-model.h5')
class_names = ['non-batagor', 'batagor']
def predict_image(image_path):
img = image.load_img(image_path, target_size=(256, 256))
img = image.img_to_array(img)
img = np.expand_dims(img, axis=0)
img /= 255.
prediction = model.predict(img)
predicted_class = np.argmax(prediction[0])
class_label = class_names[predicted_class]
confidence = prediction[0][predicted_class] * 100
print("Predicted class:", class_label)
print("Confidence: {:.3f} %\n\n".format(confidence))
if class_label == "non-batagor":
if confidence < 26:
print("Batagor")
else:
print("Bukan Batagor")
elif class_label == "batagor":
if confidence > 26:
print("Bukan Batagor")
else:
print("Batagor")
# Path gambar yang ingin diprediksi
image_path = "/content/batagor-udang.jpg"
# Melakukan prediksi pada gambar
prediction_result = predict_image(image_path)
# Menampilkan hasil prediksi
# print(prediction_result)