Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

W2d4 #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
205 changes: 205 additions & 0 deletions week-2/solo-challenges/data-augmentation.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"toc": true
},
"source": [
"<h1>Table of Contents<span class=\"tocSkip\"></span></h1>\n",
"<div class=\"toc\"><ul class=\"toc-item\"><li><span><a href=\"#Data-Augmentation\" data-toc-modified-id=\"Data-Augmentation-1\"><span class=\"toc-item-num\">1&nbsp;&nbsp;</span>Data Augmentation</a></span><ul class=\"toc-item\"><li><span><a href=\"#Code-Challenge:-Importing-Images\" data-toc-modified-id=\"Code-Challenge:-Importing-Images-1.1\"><span class=\"toc-item-num\">1.1&nbsp;&nbsp;</span>Code Challenge: Importing Images</a></span></li><li><span><a href=\"#Code-Challenge:-random_rotation\" data-toc-modified-id=\"Code-Challenge:-random_rotation-1.2\"><span class=\"toc-item-num\">1.2&nbsp;&nbsp;</span>Code Challenge: <code>random_rotation</code></a></span></li><li><span><a href=\"#Code-Challenge:-random_noise\" data-toc-modified-id=\"Code-Challenge:-random_noise-1.3\"><span class=\"toc-item-num\">1.3&nbsp;&nbsp;</span>Code Challenge: <code>random_noise</code></a></span></li><li><span><a href=\"#Code-Challenge:-mirror_image\" data-toc-modified-id=\"Code-Challenge:-mirror_image-1.4\"><span class=\"toc-item-num\">1.4&nbsp;&nbsp;</span>Code Challenge: <code>mirror_image</code></a></span></li><li><span><a href=\"#Code-Challenge:-Augmenting-Data\" data-toc-modified-id=\"Code-Challenge:-Augmenting-Data-1.5\"><span class=\"toc-item-num\">1.5&nbsp;&nbsp;</span>Code Challenge: Augmenting Data</a></span></li></ul></li><li><span><a href=\"#Extensions\" data-toc-modified-id=\"Extensions-2\"><span class=\"toc-item-num\">2&nbsp;&nbsp;</span>Extensions</a></span></li></ul></div>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Data Augmentation"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Suppose we'll be training a binary classifier to distinguish between images of cats and dogs. We've got a data set of a few thousand images of furry beasts but we'd like to augment our data set in the hopes of training a more generalizable model. We'll use this time to explore some of the image processing features of `skimage`."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import skimage as sk\n",
"from skimage import transform\n",
"from skimage import util\n",
"import numpy as np"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Code Challenge: Importing Images"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"There are zipped files containing images of cats and dogs in the directory `data/cats-and-dogs`. Unzip them and use `sk.io.imread` to try reading a few of the images. What data type is the resulting in-memory representation of the image?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# try reading some images of cats and dogs"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Code Challenge: `random_rotation`"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Using `sk.transform.rotate`, create a function that randomly rotates an image at an angle between -30 and 30 degrees."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"def random_rotate(im_array):\n",
" pass"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Code Challenge: `random_noise`"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Using `sk.util.random_noise`, create a function that adds random noise to an image."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"def random_noise(im_array):\n",
" pass"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Code Challenge: `mirror_image`"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Write a function that flips an image around the vertical axis through the center of the image. You shouldn't need any libraries."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"def mirror_image(im_array):\n",
" pass"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Code Challenge: Augmenting Data"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Come up with a plan to double the size of your data set using the functions you've created. Not every image should be treated the same way (i.e. don't apply each transformation to each image). Use `sk.io.imsave` to save your transformed images. The filenames you use should follow the format for the pre-existing images."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Use this cell to perform data augmentation"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Extensions"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Explore more of the preprocessing functionality in the `skimage` library. Are there any other transformations you want to apply to your data? You may also return to your previous unfinished hack hours."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.6.4"
},
"toc": {
"nav_menu": {},
"number_sections": true,
"sideBar": false,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": true,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.