Skip to content

Commit

Permalink
Second commit
Browse files Browse the repository at this point in the history
  • Loading branch information
saty101 authored Apr 7, 2020
1 parent 61775ea commit d6e90fb
Showing 1 changed file with 88 additions and 0 deletions.
88 changes: 88 additions & 0 deletions painting_style_classifier.ipynb
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
}

0 comments on commit d6e90fb

Please sign in to comment.