Spaces:
Runtime error
Runtime error
Download src/cnnClassfier/pipeline/predict.py from Md-Hakim/image-classification-using-mlops: direct link, hf CLI and curl.
- Browser
- Download file 752 Bytes
-
https://huggingface.co/spaces/Md-Hakim/image-classification-using-mlops/resolve/main/src/cnnClassfier/pipeline/predict.py
- Command line
-
hf download hf://spaces/Md-Hakim/image-classification-using-mlops/src/cnnClassfier/pipeline/predict.py
-
curl -L -o predict.py https://huggingface.co/spaces/Md-Hakim/image-classification-using-mlops/resolve/main/src/cnnClassfier/pipeline/predict.py
752 Bytes
| import numpy as np | |
| from tensorflow.keras.models import load_model | |
| from tensorflow.keras.preprocessing import image | |
| import os | |
| class Prediction: | |
| def __init__(self,filename): | |
| self.filename =filename | |
| def predict(self): | |
| # load model | |
| model = load_model("model.h5") | |
| imagename = self.filename | |
| test_image = image.load_img(imagename, target_size = (224,224)) | |
| test_image = image.img_to_array(test_image) | |
| test_image = np.expand_dims(test_image, axis = 0) | |
| result = np.argmax(model.predict(test_image), axis=1) | |
| print(result) | |
| if result[0] == 1: | |
| prediction = 'Healthy' | |
| else: | |
| prediction = 'Coccidiosis' | |
| return prediction |