Downloads · 30 days
0
k0e1i0i5chi/a
a is a machine learning model from k0e1i0i5chi. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
from keras.models import loadmodel TensorFlow is required for Keras to work from PIL import Image, ImageOps Install pillow instead of PIL import numpy as np
Downloads · 30 days
0
Access
Public
Updated Jan 28, 2024
Repo size
2.5 MB
Likes
0
Public
Click a slice to open those files.
.h52.5 MB · 98%
From the Hugging Face model README
from keras.models import load_model # TensorFlow is required for Keras to work from PIL import Image, ImageOps # Install pillow instead of PIL import numpy as np
import gradio as gr def image_classifier(image):
np.set_printoptions(suppress=True)
model = load_model("keras_model.h5", compile=False)
class_names = open("labels.txt", "r").readlines()
data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32)
image = Image.fromarray(image.astype("uint8"),"RGB")
size = (224, 224) image = ImageOps.fit(image, size, Image.Resampling.LANCZOS)
image_array = np.asarray(image) normalized_image_array = (image_array.astype(np.float32) / 127.5) - 1 data[0] = normalized_image_array
prediction = model.predict(data) index = np.argmax(prediction) class_name = class_names[index] confidence_score = prediction[0][index]
result = class_name[2:] return result print("Confidence Score:", confidence_score)
iface = gr.Interface( fn=image_classifier, inputs=gr.Image(), # 画像を入力として受け取ります。 outputs="text" # 結果をテキストで表示します。 )
#インターフェースを起動します。 iface.launch()