{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "Image_augmentation.ipynb",
"provenance": [],
"collapsed_sections": [],
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"accelerator": "GPU"
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
""
]
},
{
"cell_type": "code",
"metadata": {
"id": "CIR7VZ1XRBCY"
},
"source": [
"%%capture\n",
"!pip install -U imgaug"
],
"execution_count": 1,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "27DMXq3WRtIX",
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "37eec11b-047d-440d-b8e8-81afc6aac42d"
},
"source": [
"import imgaug\n",
"print(imgaug.__version__)"
],
"execution_count": 2,
"outputs": [
{
"output_type": "stream",
"text": [
"0.4.0\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "8dqBSoIUfmoN"
},
"source": [
"import imgaug.augmenters as iaa"
],
"execution_count": 3,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "0Lrs6ufwfsRh",
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "f19653eb-ba27-461b-ab61-c1bb3d7c7e32"
},
"source": [
"from torchvision import datasets\n",
"import torch\n",
"data_folder = '/content/' # This can be any directory you want to download FMNIST to\n",
"fmnist = datasets.FashionMNIST(data_folder, download=True, train=True)"
],
"execution_count": 4,
"outputs": [
{
"output_type": "stream",
"text": [
"/usr/local/lib/python3.7/dist-packages/torchvision/datasets/mnist.py:498: UserWarning: The given NumPy array is not writeable, and PyTorch does not support non-writeable tensors. This means you can write to the underlying (supposedly non-writeable) NumPy array using the tensor. You may want to copy the array to protect its data or make it writeable before converting it to a tensor. This type of warning will be suppressed for the rest of this program. (Triggered internally at /pytorch/torch/csrc/utils/tensor_numpy.cpp:180.)\n",
" return torch.from_numpy(parsed.astype(m[2], copy=False)).view(*s)\n"
],
"name": "stderr"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "uNpLxbc6gGIl"
},
"source": [
"tr_images = fmnist.data\n",
"tr_targets = fmnist.targets"
],
"execution_count": 5,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "kuGaMbCGgHsd"
},
"source": [
"import matplotlib.pyplot as plt\n",
"%matplotlib inline\n",
"import numpy as np\n",
"from torch.utils.data import Dataset, DataLoader\n",
"import torch\n",
"import torch.nn as nn\n",
"device = 'cuda' if torch.cuda.is_available() else 'cpu'\n",
"\n",
"def to_numpy(tensor):\n",
" return tensor.cpu().detach().numpy()"
],
"execution_count": 6,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "o2w1Ac2fgMEY",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 299
},
"outputId": "932f07c9-332d-4fba-bef1-f66fee9b2df0"
},
"source": [
"plt.imshow(tr_images[0], cmap='gray')\n",
"plt.title('Original image')"
],
"execution_count": 7,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"Text(0.5, 1.0, 'Original image')"
]
},
"metadata": {
"tags": []
},
"execution_count": 7
},
{
"output_type": "display_data",
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAPsAAAEICAYAAACZA4KlAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAVhUlEQVR4nO3de7DU5X3H8fdXEJWLICJ4QAY0YiWTSbBBtEpsjJdRMwnEOCT2EpjEkprLNB3t1JppQpLphJrbZBKalBgbExONTaTRiTfqNGNTMOFoCRDJBRAKCAcR5H478O0f+yOzIef3fQ67e3YXns9r5gx7ft99dp/f7vny++1+f8/zmLsjIie/U1rdARFpDiW7SCaU7CKZULKLZELJLpIJJbtIJpTsJwgzu9vM7m30fXvxWG5mF5bEnjCzmY14Hul7pj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