-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from fastai2.vision.all import *\n", | ||
"from fastai2.vision.widgets import *" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# **Painting Style Classifier**\n", | ||
"This is a painting style classifier which distinguishes a painting into 'Surrealism', 'Expressionism', 'Mughal miniature', 'Madhubani', 'Cubism' based on fastai2." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"path = Path()\n", | ||
"learn_inf = load_learner(path/'export.pkl', cpu=True)\n", | ||
"btn_upload = widgets.FileUpload()\n", | ||
"out_pl = widgets.Output()\n", | ||
"lbl_pred = widgets.Label()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def on_click(change):\n", | ||
" img = PILImage.create(btn_upload.data[-1])\n", | ||
" out_pl.clear_output()\n", | ||
" with out_pl: display(img.to_thumb(128,128))\n", | ||
" pred, pred_idx, probs = learn_inf.predict(img)\n", | ||
" lbl_pred.value = f'Prediction: {pred}; Probability: {probs[pred_idx]:.04f}'" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"btn_upload.observe(on_click, names=['data'])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"display(VBox([widgets.Label('Select your painting'), btn_upload, out_pl, lbl_pred]))" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.7.3" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |