{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Image Cleaner Widget" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "fastai offers several widgets to support the workflow of a deep learning practitioner. The purpose of the widgets are to help you organize, clean, and prepare your data for your model. Widgets are separated by data type." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide_input": true }, "outputs": [], "source": [ "from fastai.vision import *\n", "from fastai.widgets import *\n", "from fastai.gen_doc.nbdoc import *" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide_input": true }, "outputs": [], "source": [ "%reload_ext autoreload\n", "%autoreload 2" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "path = untar_data(URLs.MNIST_SAMPLE)\n", "data = ImageDataBunch.from_folder(path)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "learn = cnn_learner(data, models.resnet18, metrics=error_rate)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| epoch | \n", "train_loss | \n", "valid_loss | \n", "error_rate | \n", "time | \n", "
|---|---|---|---|---|
| 0 | \n", "0.233059 | \n", "0.115309 | \n", "0.033857 | \n", "00:10 | \n", "
| 1 | \n", "0.110543 | \n", "0.085249 | \n", "0.028459 | \n", "00:10 | \n", "
class DatasetFormatter[source][test]DatasetFormatter()\n",
"\n",
"from_similars[source][test]from_similars(**`learn`**, **`layer_ls`**:`list`=***`[0, 7, 2]`***, **\\*\\*`kwargs`**)\n",
"\n",
"from_toplosses[source][test]from_toplosses(**`learn`**, **`n_imgs`**=***`None`***, **\\*\\*`kwargs`**)\n",
"\n",
"No tests found for from_toplosses. To contribute a test please refer to this guide and this discussion.
from_most_unsure[source][test]from_most_unsure(**`learn`**:[`Learner`](/basic_train.html#Learner), **`num`**=***`50`***) → `Tuple`\\[[`DataLoader`](https://pytorch.org/docs/stable/data.html#torch.utils.data.DataLoader), `List`\\[`int`\\], `Sequence`\\[`str`\\], `List`\\[`str`\\]\\]\n",
"\n",
"No tests found for from_most_unsure. To contribute a test please refer to this guide and this discussion.
class ImageCleaner[source][test]ImageCleaner(**`dataset`**:[`LabelLists`](/data_block.html#LabelLists), **`fns_idxs`**:`Collection`\\[`int`\\], **`path`**:`PathOrStr`, **`batch_size`**=***`5`***, **`duplicates`**=***`False`***) :: [`BasicImageWidget`](/widgets.image_cleaner.html#BasicImageWidget)\n",
"\n",
"Tests found for ImageCleaner:
pytest -sv tests/test_widgets_image_cleaner.py::test_image_cleaner_index_length_mismatch [source]pytest -sv tests/test_widgets_image_cleaner.py::test_image_cleaner_length_correct [source]pytest -sv tests/test_widgets_image_cleaner.py::test_image_cleaner_with_data_from_csv [source]pytest -sv tests/test_widgets_image_cleaner.py::test_image_cleaner_wrong_input_type [source]To run tests please refer to this guide.
(n_batches, n_features, 1, 1) then you don't need any pooling (this is the case with the last layer). The suggested use of `.from_similars()` with resnets is using the last layer and no pooling, like in the following cell."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Getting activations...\n"
]
},
{
"data": {
"text/html": [
"\n",
" class PredictionsCorrector[source][test]PredictionsCorrector(**`dataset`**:[`LabelLists`](/data_block.html#LabelLists), **`fns_idxs`**:`Collection`\\[`int`\\], **`classes`**:`Sequence`\\[`str`\\], **`labels`**:`Sequence`\\[`str`\\], **`batch_size`**:`int`=***`5`***) :: [`BasicImageWidget`](/widgets.image_cleaner.html#BasicImageWidget)\n",
"\n",
"No tests found for PredictionsCorrector. To contribute a test please refer to this guide and this discussion.
| epoch | \n", "train_loss | \n", "valid_loss | \n", "accuracy | \n", "time | \n", "
|---|---|---|---|---|
| 0 | \n", "0.245369 | \n", "0.138495 | \n", "0.953610 | \n", "02:14 | \n", "
| 1 | \n", "0.133183 | \n", "0.103801 | \n", "0.963695 | \n", "02:16 | \n", "
show_corrections[source][test]show_corrections(**`ncols`**:`int`, **\\*\\*`fig_kw`**)\n",
"\n",
"No tests found for show_corrections. To contribute a test please refer to this guide and this discussion.
corrected_labels[source][test]corrected_labels() → `List`\\[`str`\\]\n",
"\n",
"No tests found for corrected_labels. To contribute a test please refer to this guide and this discussion.
class ImageDownloader[source][test]ImageDownloader(**`path`**:`PathOrStr`=***`'data'`***)\n",
"\n",
"download_google_images[source][test]download_google_images(**`path`**:`PathOrStr`, **`search_term`**:`str`, **`size`**:`str`=***`'>400*300'`***, **`n_images`**:`int`=***`10`***, **`format`**:`str`=***`'jpg'`***, **`max_workers`**:`int`=***`16`***, **`timeout`**:`int`=***`4`***) → `FilePathList`\n",
"\n",
"No tests found for download_google_images. To contribute a test please refer to this guide and this discussion.
get_toplosses_idxs[source][test]get_toplosses_idxs(**`learn`**, **`n_imgs`**, **\\*\\*`kwargs`**)\n",
"\n",
"No tests found for get_toplosses_idxs. To contribute a test please refer to this guide and this discussion.
padded_ds[source][test]padded_ds(**`ll_input`**, **`size`**=***`(250, 300)`***, **`resize_method`**=***`No tests found for padded_ds. To contribute a test please refer to this guide and this discussion.
get_similars_idxs[source][test]get_similars_idxs(**`learn`**, **`layer_ls`**, **\\*\\*`kwargs`**)\n",
"\n",
"No tests found for get_similars_idxs. To contribute a test please refer to this guide and this discussion.
get_actns[source][test]get_actns(**`learn`**, **`hook`**:[`Hook`](/callbacks.hooks.html#Hook), **`dl`**:[`DataLoader`](https://pytorch.org/docs/stable/data.html#torch.utils.data.DataLoader), **`pool`**=***`'AdaptiveConcatPool2d'`***, **`pool_dim`**:`int`=***`4`***, **\\*\\*`kwargs`**)\n",
"\n",
"No tests found for get_actns. To contribute a test please refer to this guide and this discussion.
comb_similarity[source][test]comb_similarity(**`t1`**:`Tensor`, **`t2`**:`Tensor`, **\\*\\*`kwargs`**)\n",
"\n",
"No tests found for comb_similarity. To contribute a test please refer to this guide and this discussion.
largest_indices[source][test]largest_indices(**`arr`**, **`n`**)\n",
"\n",
"No tests found for largest_indices. To contribute a test please refer to this guide and this discussion.
sort_idxs[source][test]sort_idxs(**`similarities`**)\n",
"\n",
"No tests found for sort_idxs. To contribute a test please refer to this guide and this discussion.
make_img_widget[source][test]make_img_widget(**`img`**:`bytes`, **`layout`**=***`Layout(height='250px', width='300px')`***, **`format`**=***`'jpg'`***) → `Image`\n",
"\n",
"No tests found for make_img_widget. To contribute a test please refer to this guide and this discussion.
make_button_widget[source][test]make_button_widget(**`label`**:`str`, **`handler`**:`Callable`, **`img_idx`**:`Optional`\\[`int`\\]=***`None`***, **`style`**:`str`=***`None`***, **`layout`**=***`Layout(width='auto')`***) → `Button`\n",
"\n",
"No tests found for make_button_widget. To contribute a test please refer to this guide and this discussion.
make_dropdown_widget[source][test]make_dropdown_widget(**`options`**:`Collection`\\[`T_co`\\], **`value`**, **`handler`**:`Callable`, **`img_idx`**:`Optional`\\[`int`\\]=***`None`***, **`description`**=***`''`***, **`layout`**=***`Layout(width='auto')`***) → `Dropdown`\n",
"\n",
"No tests found for make_dropdown_widget. To contribute a test please refer to this guide and this discussion.
make_horizontal_box[source][test]make_horizontal_box(**`children`**:`Collection`\\[`Widget`\\], **`layout`**=***`Layout()`***) → `HBox`\n",
"\n",
"No tests found for make_horizontal_box. To contribute a test please refer to this guide and this discussion.
make_vertical_box[source][test]make_vertical_box(**`children`**:`Collection`\\[`Widget`\\], **`layout`**=***`Layout(height='300px', overflow_x='hidden', width='auto')`***) → `VBox`\n",
"\n",
"No tests found for make_vertical_box. To contribute a test please refer to this guide and this discussion.
create_image_list[source][test]create_image_list(**`fns_idxs`**:`Collection`\\[`int`\\], **`drop_batch_on_nonfile`**=***`False`***) → `Iterator`\\[[`ImgData`](/widgets.image_cleaner.html#ImgData)\\]\n",
"\n",
"No tests found for create_image_list. To contribute a test please refer to this guide and this discussion.
next_batch[source][test]next_batch(**`_`**=***`None`***)\n",
"\n",
"No tests found for next_batch. To contribute a test please refer to this guide and this discussion.
make_payload[source][test]make_payload(**`idx`**:`int`)\n",
"\n",
"No tests found for make_payload. To contribute a test please refer to this guide and this discussion.
before_next_batch[source][test]before_next_batch(**`payloads`**:`Tuple`\\[`Mapping`\\[`KT`, `VT_co`\\]\\])\n",
"\n",
"No tests found for before_next_batch. To contribute a test please refer to this guide and this discussion.
get_widgets[source][test]get_widgets(**`batch`**:`Tuple`\\[[`ImgData`](/widgets.image_cleaner.html#ImgData)\\]) → `List`\\[`Widget`\\]\n",
"\n",
"No tests found for get_widgets. To contribute a test please refer to this guide and this discussion.
relabel[source][test]relabel(**`change`**)\n",
"\n",
"No tests found for relabel. To contribute a test please refer to this guide and this discussion.
on_delete[source][test]on_delete(**`btn`**:`Button`)\n",
"\n",
"No tests found for on_delete. To contribute a test please refer to this guide and this discussion.
delete_image[source][test]delete_image(**`file_path`**)\n",
"\n",
"No tests found for delete_image. To contribute a test please refer to this guide and this discussion.
batch_contains_deleted[source][test]batch_contains_deleted(**`batch`**:`Tuple`\\[[`ImgData`](/widgets.image_cleaner.html#ImgData)\\])\n",
"\n",
"No tests found for batch_contains_deleted. To contribute a test please refer to this guide and this discussion.
write_csv[source][test]write_csv()\n",
"\n",
"No tests found for write_csv. To contribute a test please refer to this guide and this discussion.
render[source][test]render(**`batch`**:`Tuple`\\[[`ImgData`](/widgets.image_cleaner.html#ImgData)\\])\n",
"\n",
"No tests found for render. To contribute a test please refer to this guide and this discussion.
make_payload[source][test]make_payload(**`idx`**:`int`)\n",
"\n",
"No tests found for make_payload. To contribute a test please refer to this guide and this discussion.
render[source][test]render(**`batch`**:`Tuple`\\[[`ImgData`](/widgets.image_cleaner.html#ImgData)\\])\n",
"\n",
"No tests found for render. To contribute a test please refer to this guide and this discussion.
get_widgets[source][test]get_widgets(**`batch`**:`Tuple`\\[[`ImgData`](/widgets.image_cleaner.html#ImgData)\\])\n",
"\n",
"No tests found for get_widgets. To contribute a test please refer to this guide and this discussion.
relabel[source][test]relabel(**`change`**)\n",
"\n",
"No tests found for relabel. To contribute a test please refer to this guide and this discussion.