Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error happened at variable image_files_names #2460

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions Docs: reorganize tutorial hierarchy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import os

Check failure on line 1 in Docs: reorganize tutorial hierarchy.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (D100)

Docs: reorganize tutorial hierarchy.py:1:1: D100 Missing docstring in public module
import shutil

import numpy as np
from PIL import Image

# Define the root directory and subdirectories
root_dir = 'my_new_dataset'
sub_dirs = ['sub_dir_1', 'sub_dir_2', 'sub_dir_3']
splits = ['train', 'val', 'test']

image_file_names = ['/content/torchgeo/images/geodataset.png', '/content/torchgeo/images/inria.png', '/content/torchgeo/images/vhr10.png']

IMG_SIZE = 32


# Function to create dummy input images
def create_input_image(path: str, shape: tuple[int], pixel_values: list[int]) -> None:

Check failure on line 18 in Docs: reorganize tutorial hierarchy.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (D103)

Docs: reorganize tutorial hierarchy.py:18:5: D103 Missing docstring in public function
data = np.random.choice(pixel_values, size=shape, replace=True).astype(np.uint8)
img = Image.fromarray(data)
img.save(path)


# Function to create dummy targets
def create_target_images(split: str, filename: str) -> None:

Check failure on line 25 in Docs: reorganize tutorial hierarchy.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (D103)

Docs: reorganize tutorial hierarchy.py:25:5: D103 Missing docstring in public function
target_pixel_values = range(10)
path = os.path.join(root_dir, 'target', split, filename)
create_input_image(path, (IMG_SIZE, IMG_SIZE), target_pixel_values)


# Create a new clean version when re-running the script
if os.path.exists(root_dir):
shutil.rmtree(root_dir)

# Create the directory structure
for sub_dir in sub_dirs:
for split in splits:
os.makedirs(os.path.join(root_dir, sub_dir, split), exist_ok=True)

# Create dummy data for all splits and filenames
for split in splits:
for filename in image_file_names:
create_input_image(
os.path.join(root_dir, 'image', split, filename),
(IMG_SIZE, IMG_SIZE),
range(2**16),
)
create_target_images(split, filename.replace('_', '_target_'))

# Zip directory
shutil.make_archive(root_dir, 'zip', '.', root_dir)
Loading