CIFARin PyTorch
Buy Me a Coffee☕
*My post explains CIFAR-10.
CIFAR10() can use CIFAR-10 dataset as shown below:
*Memos:
- The 1st argument is root(Required-Type:str or pathlib.Path). *An absolute or relative path is possible.
- The 2nd argument is train(Optional-Default:True-Type:bool). *If it's True, train data(50,000 images) is used while if it's False, test data(10,000 images) is used.
- The 3rd argument is transform(Optional-Default:None-Type:callable).
- The 4th argument is target_transform(Optional-Default:None-Type:callable).
- The 5th argument is download(Optional-Default:False-Type:bool):
*Memos:
- If it's True, the dataset is downloaded from the internet and extracted(unzipped) to root.
- If it's True and the dataset is already downloaded, it's extracted.
- If it's True and the dataset is already downloaded and extracted, nothing happens.
- It should be False if the dataset is already downloaded and extracted because it's faster.
- You can manually download and extract the dataset(cifar-10-python.tar.gz) from here to data/cifar-10-batches-py/.
from torchvision.datasets import CIFAR10 train_data = CIFAR10( root="data" ) train_data = CIFAR10( root="data", train=True, transform=None, target_transform=None, download=False ) test_data = CIFAR10( root="data", train=False ) len(train_data), len(test_data) # (50000, 10000) train_data # Dataset CIFAR10 # Number of datapoints: 50000 # Root location: data # Split: Train train_data.root # 'data' train_data.train # True print(train_data.transform) # None print(train_data.target_transform) # None train_data.download # bound method CIFAR10.download of Dataset CIFAR10 # Number of datapoints: 50000 # Root location: data # Split: Train> len(train_data.classes) # 10 train_data.classes # ['airplane', 'automobile', 'bird', 'cat', 'deer', # 'dog', 'frog', 'horse', 'ship', 'truck'] train_data[0] # (<PIL.Image.Image image mode=RGB size=32x32>, 6) train_data[1] # (<PIL.Image.Image image mode=RGB size=32x32>, 9) train_data[2] # (<PIL.Image.Image image mode=RGB size=32x32>, 9) train_data[3] # (<PIL.Image.Image image mode=RGB size=32x32>, 4) train_data[4] # (<PIL.Image.Image image mode=RGB size=32x32>, 1) import matplotlib.pyplot as plt def show_images(data, main_title=None): plt.figure(figsize=(10, 5)) plt.suptitle(t=main_title, y=1.0, fontsize=14) for i, (im, lab) in enumerate(data, start=1): plt.subplot(2, 5, i) plt.title(label=lab) plt.imshow(X=im) if i == 10: break plt.tight_layout() plt.show() show_images(data=train_data, main_title="train_data") show_images(data=test_data, main_title="test_data")
The above is the detailed content of CIFARin PyTorch. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Solution to permission issues when viewing Python version in Linux terminal When you try to view Python version in Linux terminal, enter python...

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...

When using Python's pandas library, how to copy whole columns between two DataFrames with different structures is a common problem. Suppose we have two Dats...

How does Uvicorn continuously listen for HTTP requests? Uvicorn is a lightweight web server based on ASGI. One of its core functions is to listen for HTTP requests and proceed...

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...

Using python in Linux terminal...

Fastapi ...

Understanding the anti-crawling strategy of Investing.com Many people often try to crawl news data from Investing.com (https://cn.investing.com/news/latest-news)...
