{
"cells": [
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"from fastai.vision.all import *\n",
"from pathlib import Path"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"learn = load_learner('model.pkl')"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"30"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"list(learn.dls.vocab).index('Emma Watson')"
]
},
{
"cell_type": "code",
"execution_count": 60,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"{'Emma Watson': tensor(0.9943),\n",
" 'Kate Beckinsale': tensor(0.0028),\n",
" 'Natalie Portman': tensor(0.0007),\n",
" 'Keira Knightley': tensor(0.0005),\n",
" 'Jessica Alba': tensor(0.0003)}"
]
},
"execution_count": 60,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"results = dict(zip(list(learn.dls.vocab),learn.predict('emma_watson.jpg')[2]))\n",
"best_results = sorted(A, key=A.get, reverse=True)[:5]\n",
"probabilities = {key: A[key] for key in best_results}\n",
"probabilities"
]
},
{
"cell_type": "code",
"execution_count": 46,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[0;31mDocstring:\u001b[0m\n",
"max(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)\n",
"\n",
"See :func:`torch.max`\n",
"\u001b[0;31mType:\u001b[0m builtin_function_or_method"
]
}
],
"source": [
"?pred.max"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"celeb_list.index('Emma Watson')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "fastai-env",
"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.11.5"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}