I am running tensorflow/serving on Windows Powershell using Docker but it keeps error like that "Failed to start server. Error: NOT_FOUND: /api/models.config/; No such file or directory". Can anyone help me with this problem?
here I am trying to run:
from fastapi import FastAPI, File, UploadFile
from fastapi.middleware.cors import CORSMiddleware
import uvicorn
import numpy as np
from io import BytesIO
from PIL import Image
import tensorflow as tf
import requests
app = FastAPI()
origins = [
"http://localhost",
"http://localhost:3000",
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
endpoint = "http://localhost:3501/v1/models/potatoes_model:predict"
CLASS_NAMES = ["Early Blight", "Late Blight", "Healthy"]
@app.get("/ping")
async def ping():
return "Hello, I am alive"
def read_file_as_image(data) -> np.ndarray:
image = np.array(Image.open(BytesIO(data)))
return image
@app.post("/predict")
async def predict(
file: UploadFile = File(...)
):
image = read_file_as_image(await file.read())
img_batch = np.expand_dims(image, 0)
json_data = {
"instances": img_batch.tolist()
}
response = requests.post(endpoint, json=json_data)
prediction = np.array(response.json()["predictions"][0])
predicted_class = CLASS_NAMES[np.argmax(prediction)]
confidence = np.max(prediction)
return {
"class": predicted_class,
"confidence": float(confidence)
}
if __name__ == "__main__":
uvicorn.run(app, host='localhost', port=8000)
I tried two ways of running it:
1. docker run -p 8000:8000 -p 3501:3501 -v type=bind,source=/Potato_disease/saved_models/,target=/Potato_disease/saved_models/ -v type=b ind,source=/Potato_disease/api/models.config/,target=/api/models.config/ -t tensorflow/serving --model_config_file=/api/models.config/
2.docker run -t --rm -p 3501:3501 -v D:\Projects\Potato_disease:\potato_disease tensorflow/serving --rest_api_port = 3501 --model_config_file=D:\Projects\Potato_disease\api\models.config
But either way it keeps error saying: There is no such file or directory.