'I am trying to load a model using pickle , but the error message is Unsuccessful TensorSliceReader constructor

FileNotFoundError: Unsuccessful TensorSliceReader constructor: Failed to find any matching files for ram://3b6a72fc-023f-4cf9-a23d-bc88571c0ef4/variables/variables 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'.

Code:

if uploadFile is not None:
    # Perform your Manupilations (In my Case applying Filters)
    img = load_image(uploadFile)
    
    image=st.image(img)
    st.write("Image Uploaded Successfully")
    cv2.imwrite('image.png',img)
    Categories=['def','nondef']

    
    model=open(r'C:\Users\28067\Desktop\work\model.p','rb')
    data = pickle.load(model) 
    
    img_pred=asarray(img)
    img_pred=np.expand_dims(img_pred,axis=0)

    rslt=data.predict(img_pred)

    st.write(rslt)
    if rslt[0][0]>rslt[0][1]:
        predictions="Defective"
    else:
        predictions="Non-defective"
    st.write(predictions)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source