This commit is contained in:
Jeremy Howard 2020-09-03 16:50:15 -07:00
parent dd985841b6
commit d93ae33d92
10 changed files with 69 additions and 90 deletions

View File

@ -660,7 +660,7 @@
} }
], ],
"source": [ "source": [
"img = PILImage.create('images/chapter1_cat_example.jpg')\n", "img = PILImage.create(image_cat())\n",
"img.to_thumb(192)" "img.to_thumb(192)"
] ]
}, },
@ -730,7 +730,7 @@
"source": [ "source": [
"#hide\n", "#hide\n",
"# For the book, we can't actually click an upload button, so we fake it\n", "# For the book, we can't actually click an upload button, so we fake it\n",
"uploader = SimpleNamespace(data = ['images/chapter1_cat_example.jpg'])" "# uploader = SimpleNamespace(data = ['images/chapter1_cat_example.jpg'])"
] ]
}, },
{ {

View File

@ -2570,7 +2570,7 @@
} }
], ],
"source": [ "source": [
"im = image2tensor(Image.open('images/grizzly.jpg'))\n", "im = image2tensor(Image.open(image_bear()))\n",
"im.shape" "im.shape"
] ]
}, },

View File

@ -158,7 +158,7 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"img = PILImage.create('images/chapter1_cat_example.jpg')\n", "img = PILImage.create(image_cat())\n",
"x, = first(dls.test_dl([img]))" "x, = first(dls.test_dl([img]))"
] ]
}, },

File diff suppressed because one or more lines are too long

View File

@ -133,7 +133,7 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"img = PILImage.create('images/chapter1_cat_example.jpg')\n", "img = PILImage.create(image_cat())\n",
"img.to_thumb(192)" "img.to_thumb(192)"
] ]
}, },
@ -162,7 +162,7 @@
"source": [ "source": [
"#hide\n", "#hide\n",
"# For the book, we can't actually click an upload button, so we fake it\n", "# For the book, we can't actually click an upload button, so we fake it\n",
"uploader = SimpleNamespace(data = ['images/chapter1_cat_example.jpg'])" "# uploader = SimpleNamespace(data = ['images/chapter1_cat_example.jpg'])"
] ]
}, },
{ {

View File

@ -472,7 +472,7 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"im = image2tensor(Image.open('images/grizzly.jpg'))\n", "im = image2tensor(Image.open(image_bear()))\n",
"im.shape" "im.shape"
] ]
}, },

View File

@ -57,7 +57,7 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"img = PILImage.create('images/chapter1_cat_example.jpg')\n", "img = PILImage.create(image_cat())\n",
"x, = first(dls.test_dl([img]))" "x, = first(dls.test_dl([img]))"
] ]
}, },

View File

@ -7,11 +7,20 @@
"outputs": [], "outputs": [],
"source": [ "source": [
"#hide\n", "#hide\n",
"!pip install -Uqq fastbook\n", "# !pip install -Uqq fastbook\n",
"import fastbook\n", "import fastbook\n",
"fastbook.setup_book()" "fastbook.setup_book()"
] ]
}, },
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from fastbook import *"
]
},
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
@ -149,7 +158,7 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"Image.open('images/chapter1_cat_example.jpg')" "Image.open(image_cat())"
] ]
}, },
{ {

View File

@ -1,64 +0,0 @@
# Numpy and pandas by default assume a narrow screen - this fixes that
from fastai.vision.all import *
from nbdev.showdoc import *
from ipywidgets import widgets
from pandas.api.types import CategoricalDtype
import matplotlib as mpl
# mpl.rcParams['figure.dpi']= 200
mpl.rcParams['savefig.dpi']= 200
mpl.rcParams['font.size']=12
set_seed(42)
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
pd.set_option('display.max_columns',999)
np.set_printoptions(linewidth=200)
torch.set_printoptions(linewidth=200)
import graphviz
def gv(s): return graphviz.Source('digraph G{ rankdir="LR"' + s + '; }')
def get_image_files_sorted(path, recurse=True, folders=None): return get_image_files(path, recurse, folders).sorted()
# +
# pip install azure-cognitiveservices-search-imagesearch
from azure.cognitiveservices.search.imagesearch import ImageSearchClient as api
from msrest.authentication import CognitiveServicesCredentials as auth
def search_images_bing(key, term, min_sz=128):
client = api('https://api.cognitive.microsoft.com', auth(key))
return L(client.images.search(query=term, count=150, min_height=min_sz, min_width=min_sz).value)
# -
def plot_function(f, tx=None, ty=None, title=None, min=-2, max=2, figsize=(6,4)):
x = torch.linspace(min,max)
fig,ax = plt.subplots(figsize=figsize)
ax.plot(x,f(x))
if tx is not None: ax.set_xlabel(tx)
if ty is not None: ax.set_ylabel(ty)
if title is not None: ax.set_title(title)
# +
from sklearn.tree import export_graphviz
def draw_tree(t, df, size=10, ratio=0.6, precision=0, **kwargs):
s=export_graphviz(t, out_file=None, feature_names=df.columns, filled=True, rounded=True,
special_characters=True, rotate=False, precision=precision, **kwargs)
return graphviz.Source(re.sub('Tree {', f'Tree {{ size={size}; ratio={ratio}', s))
# +
from scipy.cluster import hierarchy as hc
def cluster_columns(df, figsize=(10,6), font_size=12):
corr = np.round(scipy.stats.spearmanr(df).correlation, 4)
corr_condensed = hc.distance.squareform(1-corr)
z = hc.linkage(corr_condensed, method='average')
fig = plt.figure(figsize=figsize)
hc.dendrogram(z, labels=df.columns, orientation='left', leaf_font_size=font_size)
plt.show()

Binary file not shown.