FileNotFoundError: Unsuccessful TensorSliceReader constructor: Failed to find any matching files for ../Saved_Model/1variablesvariables
Question:
I am trying to build a image classifier API. Built the model using Google Colab becasue i dont have a GPU. Am using CPU and donwloaded the model into the API application.
But get this error when i try to access my model directory Saved_Model.
I know its to do with GPU and CUDA settings but i cant tell what exaclty is wrong or how sort it since am using CPU.
Complete Error:
Elijah-A-W@DESKTOP-34M2E8U MINGW64 /d/myn/ML Prediction Project/New folder/Detection Potato Lite/Api
$ python main.py
2022-07-29 09:12:32.654485: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library
'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2022-07-29 09:12:32.670439: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not
have a GPU set up on your machine.
2022-07-29 09:13:18.928444: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library
'nvcuda.dll'; dlerror: nvcuda.dll not found
2022-07-29 09:13:18.928809: W tensorflow/stream_executor/cuda/cuda_driver.cc:269] failed call to cuInit: UNKNOWN ERROR (303)
2022-07-29 09:13:18.934497: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:169] retrieving CUDA diagnostic information for host: DESKTOP-34M2E8U
2022-07-29 09:13:18.935291: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:176] hostname: DESKTOP-34M2E8U
2022-07-29 09:13:19.068867: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
Traceback (most recent call last):
File "D:mynML Prediction ProjectNew folderDetection Potato LiteApimain.py", line 10, in <module>
MODEL = tf.keras.models.load_model("../Saved_Model/1")
File "C:UsersElijah-A-WAppDataLocalProgramsPythonPython310libsite-packageskerasutilstraceback_utils.py", line 67, in error_handler
raise e.with_traceback(filtered_tb) from None
File "C:UsersElijah-A-WAppDataLocalProgramsPythonPython310libsite-packagestensorflowpythonsaved_modelload.py", line 915, in load_partial
raise FileNotFoundError(
FileNotFoundError: Unsuccessful TensorSliceReader constructor: Failed to find any matching files for ../Saved_Model/1variablesvariables
You may be trying to load on a different device from the computational device. Consider setting the `experimental_io_device` option in `tf.saved_model.LoadOptions` to the io_device such as '/job:localhost'.
The Complete code:
from fastapi import FastAPI, File, UploadFile
import uvicorn
import numpy as np
from io import BytesIO
from PIL import Image
import tensorflow as tf
app = FastAPI()
MODEL = tf.keras.models.load_model("../Saved_Model/1")
CLASS_NAMES = ["Early Blight", "Late Blight", "Healthy"]
@app.get("/ping")
async def ping():
return "hello, I am alive"
async def read_file_as_image(data) -> np.ndarray:
image = np.array(Image.open(BytesIO(data))) # reading an image as byte & converting into array
img_batch = np.expand_dims(image, 0) # adding extra dimesnion to the loaded img batch
prediction = MODEL.predict(img_batch) # calling the model predict the image batch
pass
@app.post("/predict")
async def predict(file: UploadFile = File(...)):
image = read_file_as_image(await file.read())
return image
if __name__ == "__main__":
uvicorn.run(app, host='localhost', port=5000)
This is the image of the Project directories
[![enter image description here][1]][1]
This is the
[1]: https://i.stack.imgur.com/Y4Bg0.png
Answers:
Didn’t manage to solve this error,so decided to train & save the model on my local machine then called it. It works fine.
I had the same issue and tried this.
Then it worked.
from keras.models import load_model
model.save('model.h5')
model_final = load_model('model.h5')
I am trying to build a image classifier API. Built the model using Google Colab becasue i dont have a GPU. Am using CPU and donwloaded the model into the API application.
But get this error when i try to access my model directory Saved_Model.
I know its to do with GPU and CUDA settings but i cant tell what exaclty is wrong or how sort it since am using CPU.
Complete Error:
Elijah-A-W@DESKTOP-34M2E8U MINGW64 /d/myn/ML Prediction Project/New folder/Detection Potato Lite/Api
$ python main.py
2022-07-29 09:12:32.654485: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library
'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2022-07-29 09:12:32.670439: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not
have a GPU set up on your machine.
2022-07-29 09:13:18.928444: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library
'nvcuda.dll'; dlerror: nvcuda.dll not found
2022-07-29 09:13:18.928809: W tensorflow/stream_executor/cuda/cuda_driver.cc:269] failed call to cuInit: UNKNOWN ERROR (303)
2022-07-29 09:13:18.934497: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:169] retrieving CUDA diagnostic information for host: DESKTOP-34M2E8U
2022-07-29 09:13:18.935291: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:176] hostname: DESKTOP-34M2E8U
2022-07-29 09:13:19.068867: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
Traceback (most recent call last):
File "D:mynML Prediction ProjectNew folderDetection Potato LiteApimain.py", line 10, in <module>
MODEL = tf.keras.models.load_model("../Saved_Model/1")
File "C:UsersElijah-A-WAppDataLocalProgramsPythonPython310libsite-packageskerasutilstraceback_utils.py", line 67, in error_handler
raise e.with_traceback(filtered_tb) from None
File "C:UsersElijah-A-WAppDataLocalProgramsPythonPython310libsite-packagestensorflowpythonsaved_modelload.py", line 915, in load_partial
raise FileNotFoundError(
FileNotFoundError: Unsuccessful TensorSliceReader constructor: Failed to find any matching files for ../Saved_Model/1variablesvariables
You may be trying to load on a different device from the computational device. Consider setting the `experimental_io_device` option in `tf.saved_model.LoadOptions` to the io_device such as '/job:localhost'.
The Complete code:
from fastapi import FastAPI, File, UploadFile
import uvicorn
import numpy as np
from io import BytesIO
from PIL import Image
import tensorflow as tf
app = FastAPI()
MODEL = tf.keras.models.load_model("../Saved_Model/1")
CLASS_NAMES = ["Early Blight", "Late Blight", "Healthy"]
@app.get("/ping")
async def ping():
return "hello, I am alive"
async def read_file_as_image(data) -> np.ndarray:
image = np.array(Image.open(BytesIO(data))) # reading an image as byte & converting into array
img_batch = np.expand_dims(image, 0) # adding extra dimesnion to the loaded img batch
prediction = MODEL.predict(img_batch) # calling the model predict the image batch
pass
@app.post("/predict")
async def predict(file: UploadFile = File(...)):
image = read_file_as_image(await file.read())
return image
if __name__ == "__main__":
uvicorn.run(app, host='localhost', port=5000)
This is the image of the Project directories
[![enter image description here][1]][1]
This is the
[1]: https://i.stack.imgur.com/Y4Bg0.png
Didn’t manage to solve this error,so decided to train & save the model on my local machine then called it. It works fine.
I had the same issue and tried this.
Then it worked.
from keras.models import load_model
model.save('model.h5')
model_final = load_model('model.h5')