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

images source #2558

Merged
merged 4 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions crates/burn-dataset/src/vision/image_folder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ pub struct ImageDatasetItem {

/// Annotation for the image.
pub annotation: Annotation,

/// Original image source.
pub image_path: String,
}

/// Raw annotation types.
Expand Down Expand Up @@ -250,6 +253,7 @@ impl Mapper<ImageDatasetItemRaw, ImageDatasetItem> for PathToImageDatasetItem {
ImageDatasetItem {
image: img_vec,
annotation,
image_path: item.image_path.display().to_string(),
}
}
}
Expand Down
10 changes: 9 additions & 1 deletion examples/custom-image-dataset/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub struct ClassificationBatcher<B: Backend> {
pub struct ClassificationBatch<B: Backend> {
pub images: Tensor<B, 4>,
pub targets: Tensor<B, 1, Int>,
pub images_path: Vec<String>,
}

impl<B: Backend> ClassificationBatcher<B> {
Expand Down Expand Up @@ -83,6 +84,9 @@ impl<B: Backend> Batcher<ImageDatasetItem, ClassificationBatch<B>> for Classific
})
.collect();

// Original sample path
let images_path: Vec<String> = items.iter().map(|item| item.image_path.clone()).collect();

let images = items
.into_iter()
.map(|item| TensorData::new(image_as_vec_u8(item), Shape::new([32, 32, 3])))
Expand All @@ -100,6 +104,10 @@ impl<B: Backend> Batcher<ImageDatasetItem, ClassificationBatch<B>> for Classific

let images = self.normalizer.normalize(images);

ClassificationBatch { images, targets }
ClassificationBatch {
images,
targets,
images_path,
}
}
}