Buy Me a Coffee☕
*My post explains QMNIST.
QMNIST() can use QMNIST 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 what(Optional-Default:None-Type:str). *"train"(60,000 images), "test"(60,000 images), "test10k"(10,000 images), "test50k"(50,000 images) or "nist"(402,953 images) can be set to it.
- The 3rd argument is compat(Optional-Default:True-Type:bool). *If it's True, the class number of each image is returnd(for compatibility with the MNIST dataloader) while if it's False, the 1D tensor of the full qmnist information is returned.
- The 4th argument is train argument(Optional-Default:True-Type:bool):
*Memos:
- It's ignored if what isn't None.
- If it's True, train data(60,000 images) is used while if it's False, test data(60,000 images) is used.
- There is transform argument(Optional-Default:None-Type:callable). *transform= must be used.
- There is target_transform argument(Optional-Default:None-Type:callable). *target_transform= must be used.
- There is download argument(Optional-Default:False-Type:bool):
*Memos:
- download= must be used.
- 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 from here to e.g. data/QMNIST/raw/.
from torchvision.datasets import QMNIST train_data = QMNIST( root="data" ) train_data = QMNIST( root="data", what=None, compat=True, train=True, transform=None, target_transform=None, download=False ) train_data = QMNIST( root="data", what="train", train=False ) test_data1 = QMNIST( root="data", train=False ) test_data1 = QMNIST( root="data", what="test", train=True ) test_data2 = QMNIST( root="data", what="test10k" ) test_data3 = QMNIST( root="data", what="test50k", compat=False ) nist_data = QMNIST( root="data", what="nist" ) l = len l(train_data), l(test_data1), l(test_data2), l(test_data3), l(nist_data) # (60000, 60000, 10000, 50000, 402953) train_data # Dataset QMNIST # Number of datapoints: 60000 # Root location: data # Split: train train_data.root # 'data' train_data.what # 'train' train_data.compat # True train_data.train # True print(train_data.transform) # None print(train_data.target_transform) # None train_data.download # <bound method qmnist.download of dataset qmnist number datapoints: root location: data split: train> train_data[0] # (<pil.image.image image mode="L" size="28x28">, 5) test_data3[0] # (<pil.image.image image mode="L" size="28x28">, # tensor([3, 4, 2424, 51, 33, 261051, 0, 0])) train_data[1] # (<pil.image.image image mode="L" size="28x28">, 0) test_data3[1] # (<pil.image.image image mode="L" size="28x28">, # tensor([8, 1, 522, 60, 38, 55979, 0, 0])) train_data[2] # (<pil.image.image image mode="L" size="28x28">, 4) test_data3[2] # (<pil.image.image image mode="L" size="28x28">, # tensor([9, 4, 2496, 115, 39, 269531, 0, 0])) train_data[3] # (<pil.image.image image mode="L" size="28x28">, 1) test_data3[3] # (<pil.image.image image mode="L" size="28x28">, # tensor([5, 4, 2427, 77, 35, 261428, 0, 0])) train_data[4] # (<pil.image.image image mode="L" size="28x28">, 9) test_data3[4] # (<pil.image.image image mode="L" size="28x28">, # tensor([7, 4, 2524, 69, 37, 272828, 0, 0])) train_data.classes # ['0 - zero', '1 - one', '2 - two', '3 - three', '4 - four', # '5 - five', '6 - six', '7 - seven', '8 - eight', '9 - nine'] </pil.image.image></pil.image.image></pil.image.image></pil.image.image></pil.image.image></pil.image.image></pil.image.image></pil.image.image></pil.image.image></pil.image.image></bound>
from torchvision.datasets import QMNIST train_data = QMNIST( root="data", what="train" ) test_data1 = QMNIST( root="data", what="test" ) test_data2 = QMNIST( root="data", what="test10k" ) test_data3 = QMNIST( root="data", what="test50k" ) nist_data = QMNIST( root="data", what="nist" ) import matplotlib.pyplot as plt def show_images(data): plt.figure(figsize=(12, 2)) col = 5 for i, (image, label) in enumerate(data, 1): plt.subplot(1, col, i) plt.title(label) plt.imshow(image) if i == col: break plt.show() show_images(data=train_data) show_images(data=test_data1) show_images(data=test_data2) show_images(data=test_data3) show_images(data=nist_data)
The above is the detailed content of QMNIST in PyTorch. For more information, please follow other related articles on the PHP Chinese website!

Article discusses impossibility of tuple comprehension in Python due to syntax ambiguity. Alternatives like using tuple() with generator expressions are suggested for creating tuples efficiently.(159 characters)

The article explains modules and packages in Python, their differences, and usage. Modules are single files, while packages are directories with an __init__.py file, organizing related modules hierarchically.

Article discusses docstrings in Python, their usage, and benefits. Main issue: importance of docstrings for code documentation and accessibility.

Article discusses lambda functions, their differences from regular functions, and their utility in programming scenarios. Not all languages support them.

Article discusses break, continue, and pass in Python, explaining their roles in controlling loop execution and program flow.

The article discusses the 'pass' statement in Python, a null operation used as a placeholder in code structures like functions and classes, allowing for future implementation without syntax errors.

Article discusses passing functions as arguments in Python, highlighting benefits like modularity and use cases such as sorting and decorators.

Article discusses / and // operators in Python: / for true division, // for floor division. Main issue is understanding their differences and use cases.Character count: 158


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

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

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

Zend Studio 13.0.1
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Atom editor mac version download
The most popular open source editor
