deep-learning/practical-deep-learning-for-coders/lesson-2/predict.py

12 lines
444 B
Python
Raw Normal View History

2024-05-09 12:23:58 +00:00
import os
from fastai.learner import load_learner
from pathlib import Path
path = Path(os.path.dirname(os.path.realpath(__file__)))
# Make sure to export the model first via the notebook.
# The exported model is not included in the repository.
model = load_learner(path/'export.pkl')
prediction, index, probabilities = model.predict(path/'test-images/grizzly.jpg')
print(f'Prediction: {prediction}, Probability: {probabilities[index]:0.4f}')