{
"cells": [
{
"cell_type": "markdown",
"id": "013df7bd-6b5f-4fd6-8ad0-62d05bd46e34",
"metadata": {},
"source": [
"# Fastai Environment Validation"
]
},
{
"cell_type": "markdown",
"id": "93f9190c-31af-4b0e-945c-23ada2d37cdd",
"metadata": {},
"source": [
"This notebook validates your Fastai environment. This assumes you have a default installation of Fastai with all dependencies and datasets and the environment was built using the example `.yml` file. Open this notebook with the `fastai` kernel to verify your environment."
]
},
{
"cell_type": "markdown",
"id": "3c76f580-82af-4caa-ac38-6394910fa92d",
"metadata": {},
"source": [
"### Import Packages\n",
"Make sure you can import packages without any errors"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "23ef4b76-74f3-42a6-8e42-a0676568affa",
"metadata": {},
"outputs": [],
"source": [
"from fastai.vision.all import *"
]
},
{
"cell_type": "markdown",
"id": "98e71ef0-7a01-465d-b23d-f0e52bfb7a99",
"metadata": {},
"source": [
"### Extract Data \n",
"Verify you can extract the sample datasets to your local directories "
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "e8803cdd-0087-4f6e-9348-6766198e9a09",
"metadata": {},
"outputs": [],
"source": [
"path = untar_data(URLs.PETS)/'images'"
]
},
{
"cell_type": "markdown",
"id": "4c168baa-bc32-43ec-bb5c-05614694167a",
"metadata": {},
"source": [
"### Define a Dataloader\n",
"Define a `fastai` dataloader and specify a validation set"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "74229bf3-5c2f-4440-a642-459dd13907b7",
"metadata": {},
"outputs": [],
"source": [
"def is_cat(x): return x[0].isupper()\n",
"dls = ImageDataLoaders.from_name_func(\n",
" path, get_image_files(path), valid_pct=0.2, seed=42,\n",
" label_func=is_cat, item_tfms=Resize(224))"
]
},
{
"cell_type": "markdown",
"id": "ab1faa2b-3a30-41c7-a8d0-9c759da8bf30",
"metadata": {},
"source": [
"### Train a Classifier\n",
"Create a fastai learner and run a training (finetuning)job for 1 epoch using the dataloader"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "373b3f26-9d3f-4fa7-ade3-7d2ba66fe51b",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
" \n",
" \n",
" epoch | \n",
" train_loss | \n",
" valid_loss | \n",
" error_rate | \n",
" time | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 0.167120 | \n",
" 0.026278 | \n",
" 0.008119 | \n",
" 00:30 | \n",
"
\n",
" \n",
"
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
" \n",
" \n",
" epoch | \n",
" train_loss | \n",
" valid_loss | \n",
" error_rate | \n",
" time | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 0.061470 | \n",
" 0.010634 | \n",
" 0.003383 | \n",
" 00:35 | \n",
"
\n",
" \n",
"
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"learn = cnn_learner(dls, resnet34, metrics=error_rate)\n",
"learn.fine_tune(1)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "fastai:Python",
"language": "python",
"name": "conda-env-fastai-py"
},
"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.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}