File size: 882 Bytes
2fed88f |
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 |
from fastapi import FastAPI, File, UploadFile
import tensorflow as tf
from PIL import Image
import numpy as np
# Model yükleme
model = tf.keras.models.load_model("face_shape_model.h5")
# FastAPI başlat
app = FastAPI()
# Görsel veriyi tahmin için işleme
def preprocess_image(image):
image = image.resize((224, 224)) # Model input boyutuna göre değiştir
image = np.array(image) / 255.0 # Normalize et
image = np.expand_dims(image, axis=0) # Batch boyutunu ekle
return image
@app.post("/predict/")
async def predict(file: UploadFile = File(...)):
# Dosyayı oku ve işleme
image = Image.open(file.file)
processed_image = preprocess_image(image)
prediction = model.predict(processed_image)
predicted_class = np.argmax(prediction, axis=1)[0] # En yüksek olasılıklı sınıfı al
return {"predicted_class": int(predicted_class)}
|