search

Flowers in PyTorch

Dec 16, 2024 pm 04:40 PM

Buy Me a Coffee☕

*My post explains Oxford 102 Flower.

Flowers102() can use Oxford 102 Flower 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 split(Optional-Default:"train"-Type:str). *"train"(1,020 images), "val"(1,020 images) or "test"(6,149 images) can be set to it.
  • 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(102flowers.tgz with imagelabels.mat and setid.matff from here to data/flowers-102/.
  • About the label from the categories(classes) for the train and validation image indices, 0 is 0~9, 1 is 10~19, 2 is 20~29, 3 is 30~39, 4 is 40~49, 5 is 50~59, 6 is 60~69, 7 is 70~79, 8 is 80~89, 9 is 90~99, etc.
  • About the label from the categories(classes) for the test image indices, 0 is 0~19, 1 is 20~59, 2 is 60~79, 3 is 80~115, 4 is 116~160, 5 is 161~185, 6 is 186~205, 7 is 206~270, 8 is 271~296, 9 is 297~321, etc.
from torchvision.datasets import Flowers102

train_data = Flowers102(
    root="data"
)

train_data = Flowers102(
    root="data",
    split="train",
    transform=None,
    target_transform=None,
    download=False
)

val_data = Flowers102(
    root="data",
    split="val"
)

test_data = Flowers102(
    root="data",
    split="test"
)

len(train_data), len(val_data), len(test_data)
# (1020, 1020, 6149)

train_data
# Dataset Flowers102
#     Number of datapoints: 1020
#     Root location: data
#     split=train

train_data.root
# 'data'

train_data._split
# 'train'

print(train_data.transform)
# None

print(train_data.target_transform)
# None

train_data.download
# <bound method flowers102.download of dataset flowers102 number datapoints: root location: data split="train">

len(set(train_data._labels)), train_data._labels
# (102,
#  [0, 0, 0, ..., 1, ..., 2, ..., 3, ..., 4, ..., 5, ..., 6, ..., 101])

train_data[0]
# (<pil.image.image image mode="RGB" size="754x500">, 0)

train_data[1]
# (<pil.image.image image mode="RGB" size="624x500">, 0)

train_data[2]
# (<pil.image.image image mode="RGB" size="667x500">, 0)

train_data[10]
# (<pil.image.image image mode="RGB" size="500x682">, 1)

train_data[20]
# (<pil.image.image image mode="RGB" size="667x500">, 2)

val_data[0]
# (<pil.image.image image mode="RGB" size="606x500">, 0)

val_data[1]
# (<pil.image.image image mode="RGB" size="667x500">, 0)

val_data[2]
# (<pil.image.image image mode="RGB" size="500x628">, 0)

val_data[10]
# (<pil.image.image image mode="RGB" size="500x766">, 1)

val_data[20]
# (<pil.image.image image mode="RGB" size="624x500">, 2)

test_data[0]
# (<pil.image.image image mode="RGB" size="523x500">, 0)

test_data[1]
# (<pil.image.image image mode="RGB" size="666x500">, 0)

test_data[2]
# (<pil.image.image image mode="RGB" size="595x500">, 0)

test_data[20]
# (<pil.image.image image mode="RGB" size="500x578">, 1)

test_data[60]
# (<pil.image.image image mode="RGB" size="500x625">, 2)

import matplotlib.pyplot as plt

def show_images(data, ims, main_title=None):
    plt.figure(figsize=(10, 5))
    plt.suptitle(t=main_title, y=1.0, fontsize=14)
    for i, j in enumerate(ims, start=1):
        plt.subplot(2, 5, i)
        im, lab = data[j]
        plt.imshow(X=im)
        plt.title(label=lab)
    plt.tight_layout()
    plt.show()

train_ims = (0, 1, 2, 10, 20, 30, 40, 50, 60, 70)
val_ims = (0, 1, 2, 10, 20, 30, 40, 50, 60, 70)
test_ims = (0, 1, 2, 20, 60, 80, 116, 161, 186, 206)

show_images(data=train_data, ims=train_ims, main_title="train_data")
show_images(data=train_data, ims=val_ims, main_title="val_data")
show_images(data=test_data, ims=test_ims, main_title="test_data")
</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></pil.image.image></pil.image.image></pil.image.image></pil.image.image></pil.image.image></bound>

Flowers in PyTorch

Flowers in PyTorch

Flowers in PyTorch

The above is the detailed content of Flowers in PyTorch. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Python's Execution Model: Compiled, Interpreted, or Both?Python's Execution Model: Compiled, Interpreted, or Both?May 10, 2025 am 12:04 AM

Pythonisbothcompiledandinterpreted.WhenyourunaPythonscript,itisfirstcompiledintobytecode,whichisthenexecutedbythePythonVirtualMachine(PVM).Thishybridapproachallowsforplatform-independentcodebutcanbeslowerthannativemachinecodeexecution.

Is Python executed line by line?Is Python executed line by line?May 10, 2025 am 12:03 AM

Python is not strictly line-by-line execution, but is optimized and conditional execution based on the interpreter mechanism. The interpreter converts the code to bytecode, executed by the PVM, and may precompile constant expressions or optimize loops. Understanding these mechanisms helps optimize code and improve efficiency.

What are the alternatives to concatenate two lists in Python?What are the alternatives to concatenate two lists in Python?May 09, 2025 am 12:16 AM

There are many methods to connect two lists in Python: 1. Use operators, which are simple but inefficient in large lists; 2. Use extend method, which is efficient but will modify the original list; 3. Use the = operator, which is both efficient and readable; 4. Use itertools.chain function, which is memory efficient but requires additional import; 5. Use list parsing, which is elegant but may be too complex. The selection method should be based on the code context and requirements.

Python: Efficient Ways to Merge Two ListsPython: Efficient Ways to Merge Two ListsMay 09, 2025 am 12:15 AM

There are many ways to merge Python lists: 1. Use operators, which are simple but not memory efficient for large lists; 2. Use extend method, which is efficient but will modify the original list; 3. Use itertools.chain, which is suitable for large data sets; 4. Use * operator, merge small to medium-sized lists in one line of code; 5. Use numpy.concatenate, which is suitable for large data sets and scenarios with high performance requirements; 6. Use append method, which is suitable for small lists but is inefficient. When selecting a method, you need to consider the list size and application scenarios.

Compiled vs Interpreted Languages: pros and consCompiled vs Interpreted Languages: pros and consMay 09, 2025 am 12:06 AM

Compiledlanguagesofferspeedandsecurity,whileinterpretedlanguagesprovideeaseofuseandportability.1)CompiledlanguageslikeC arefasterandsecurebuthavelongerdevelopmentcyclesandplatformdependency.2)InterpretedlanguageslikePythonareeasiertouseandmoreportab

Python: For and While Loops, the most complete guidePython: For and While Loops, the most complete guideMay 09, 2025 am 12:05 AM

In Python, a for loop is used to traverse iterable objects, and a while loop is used to perform operations repeatedly when the condition is satisfied. 1) For loop example: traverse the list and print the elements. 2) While loop example: guess the number game until you guess it right. Mastering cycle principles and optimization techniques can improve code efficiency and reliability.

Python concatenate lists into a stringPython concatenate lists into a stringMay 09, 2025 am 12:02 AM

To concatenate a list into a string, using the join() method in Python is the best choice. 1) Use the join() method to concatenate the list elements into a string, such as ''.join(my_list). 2) For a list containing numbers, convert map(str, numbers) into a string before concatenating. 3) You can use generator expressions for complex formatting, such as ','.join(f'({fruit})'forfruitinfruits). 4) When processing mixed data types, use map(str, mixed_list) to ensure that all elements can be converted into strings. 5) For large lists, use ''.join(large_li

Python's Hybrid Approach: Compilation and Interpretation CombinedPython's Hybrid Approach: Compilation and Interpretation CombinedMay 08, 2025 am 12:16 AM

Pythonusesahybridapproach,combiningcompilationtobytecodeandinterpretation.1)Codeiscompiledtoplatform-independentbytecode.2)BytecodeisinterpretedbythePythonVirtualMachine,enhancingefficiencyandportability.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment