Learn practical skills, build real-world projects, and advance your career
# This Python 3 environment comes with many helpful analytics libraries installed
# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python
# For example, here's several helpful packages to load

import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

# Input data files are available in the read-only "../input/" directory
# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory

import os
for dirname, _, filenames in os.walk('/kaggle/input'):
    for filename in filenames:
        print(os.path.join(dirname, filename))

# You can write up to 5GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using "Save & Run All" 
# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session

I have chosen a problem of image classification of 7 types of nuts (-almonds, -hazelnuts, -macadamias, -peanuts, -pecans, -pistachios, -walnuts)

Lots of people are allergic to some particular kind of nuts, so this task can have a real-world application, if I will be able to achieve acceptable level of error (No more than 15%).

In this attempt#2 I used knowledge from the Course "Pytorch from zero to GANS", based on Jovian

For this code I will need much more import,than in first attempt, code as follows:

import os
import torch
import torchvision
import tarfile
import torch.nn as nn
import numpy as np
import torch.nn.functional as F

from torchvision.datasets.utils import download_url
from torchvision.datasets import ImageFolder
from torch.utils.data import DataLoader
import torchvision.transforms as tt
from torch.utils.data import random_split
from torchvision.utils import make_grid
import matplotlib.pyplot as plt
%matplotlib inline

Data downloading

But for download I will use fastai library just as in my attempt#1
Dataset
I have created my own dataset of urls of images, using Google search for pictures of 7 types of nuts:
-almonds -hazelnuts -macadamias -peanuts -pecans -pistachios -walnuts.

How to download?

I have searched pictures of particular kind of nuts in Google Images (do not forget press "show more" buttom, to retrieve more pictures, at least 200 of every type of ).

Than I have downloaded Urls of those images, using following script:

In Google Chrome press CtrlShiftj on Windows/Linux and CmdOptj on macOS, and a small window the javascript 'Console' will appear. In Firefox press CtrlShiftk on Windows/Linux or CmdOptk on macOS. That is where you will paste the JavaScript commands.

urls=Array.from(document.querySelectorAll('.rg_i')).map(el=> el.hasAttribute('data-src')?el.getAttribute('data-src'):el.getAttribute('data-iurl')); window.open('data:text/csv;charset=utf-8,' + escape(urls.join('\n')));

As a result I have dowmloaded to my local computer 1 file .csv type per class of nuts.

Using Kaggle, I have downloaded theese 7 .csv files to my own Dataset ("+Add data" on the right side , press "Download"). Now I have my own dataset on Kaggle https://www.kaggle.com/dariashenkevych/nuts-1 . every time I run my notebook I should choose this dataset again, but no need to download it again.
This dataset "nuts-1" is in the directory Input.