Spaces:
Sleeping
Sleeping
Pashtetuum
commited on
Commit
•
23fd2ea
1
Parent(s):
53e2b84
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import random
|
3 |
+
import numpy as np
|
4 |
+
import matplotlib.pyplot as plt
|
5 |
+
from tensorflow.keras.models import load_model
|
6 |
+
from tensorflow.keras.preprocessing.image import load_img, img_to_array
|
7 |
+
#Загружаем модель
|
8 |
+
loaded_model = load_model('E:/Python/AutokerasOUT/image_classifier/best_model', custom_objects=ak.CUSTOM_OBJECTS)
|
9 |
+
# Загружаем label_encoder
|
10 |
+
with open('C:/Users/filim/Python/label_encoder.pkl', 'rb') as le_file:
|
11 |
+
label_encoder = pickle.load(le_file)
|
12 |
+
def translator(Defect):
|
13 |
+
translation_dict = {
|
14 |
+
"Crazing": "Трещины",
|
15 |
+
"Inclusion": "Вкрапления",
|
16 |
+
"Patches": "Пятна",
|
17 |
+
"Pitted": "Рябь",
|
18 |
+
"Rolled": "Замятие",
|
19 |
+
"Scratches": "Царапины"
|
20 |
+
}
|
21 |
+
return translation_dict.get(Defect)
|
22 |
+
def predict(loaded_img):
|
23 |
+
# Изменение размера изображения
|
24 |
+
img = cv2.resize(loaded_img, (200, 200))
|
25 |
+
# Добавление измерения пакета
|
26 |
+
img_array = np.expand_dims(img, axis=0)
|
27 |
+
# Предсказание класса
|
28 |
+
prediction = loaded_model.predict(img_array)
|
29 |
+
predicted_class = np.argmax(prediction)
|
30 |
+
decoded_class = label_encoder.inverse_transform([predicted_class])[0]
|
31 |
+
prediction=translator(decoded_class)
|
32 |
+
return prediction
|
33 |
+
|
34 |
+
interface = gr.Interface(
|
35 |
+
fn=predict,
|
36 |
+
inputs=gr.Image(),
|
37 |
+
outputs=gr.Textbox(label="Предсказанный класс"),
|
38 |
+
title="Нейронная сеть для классификации брака на металлопрокате"
|
39 |
+
)
|
40 |
+
|
41 |
+
interface.launch()
|