{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Autoreload problem with fastai \n", "this notebook reproduces the failure of autoreload fastai library on its update after the notebook has started, which breaks it. at least with the Learner object." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%reload_ext autoreload\n", "%autoreload 2\n", "%matplotlib inline" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import sys, pickle\n", "from pathlib import Path" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# CHANGE REQUIRED: adjust the path to where fastai repo is checked out\n", "FASTAI_REPO = Path(\"/mnt/nvme1/fast.ai-1/br/fastai/master\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "TARGET = FASTAI_REPO/\"fastai\"/\"basic_train.py\"\n", "sys.path.insert(1, str(FASTAI_REPO))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from fastai.vision import *\n", "from fastai.datasets import *\n", "from fastai.metrics import *" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "path = untar_data(URLs.MNIST_TINY)\n", "data = ImageDataBunch.from_folder(path, ds_tfms=(rand_pad(2, 28), []))\n", "learn = create_cnn(data, models.resnet18, metrics=[accuracy])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# touch forces autoreloader to reloading TARGET fastai python library \n", "!echo touch $TARGET\n", "!touch $TARGET" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# this works if the previous cell didn't run\n", "p = pickle.dumps(learn)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# cleanup\n", "!rm export.pkl\n", "!rmdir models" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" } }, "nbformat": 4, "nbformat_minor": 2 }