See the full explanation behind this demonstration notebook at FastAI quick test / LeafSnap.
from google.colab import drive
drive.mount('/content/gdrive')
from pathlib import Path
drive_path = Path('/content/gdrive/My Drive/leafsnap')
base_path = Path('/content/leafsnap-dataset')
!pip install "torch==1.4" "torchvision==0.5.0"
%reload_ext autoreload
%autoreload 2
%matplotlib inline
from fastai.vision import *
from fastai.metrics import error_rate
img = open_image(drive_path/'maple.jpg')
img
model_rn34 = load_learner(drive_path, 'leafsnap-rn34-4e-ft1-ft8.pkl')
pred_class, pred_idx, outputs = model_rn34.predict(img)
pred_class.obj
def predict_file(file_name):
img = open_image(drive_path/file_name)
pred_class, pred_idx, outputs = model_rn34.predict(img)
img.show(title=f'Prediction: {pred_class.obj}, with {outputs.max()*100:2.0f}% confidence', figsize=(10,10))
predict_file('maple.jpg')
predict_file('spruce.jpg')
predict_file('lilac.jpg')
predict_file('unknown_1.jpg')
predict_file('unknown_2.jpg')
predict_file('unknown_3.jpg')