You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My geotiff data is typically multispectral and I do experiments using subsets of the channels. I would like to stream only the required channels in order to save bandwidth
Pitch
Select e.g. channels 1,3,5 to stream
Alternatives
I can list the channels as separate files, and then access only those I require
Additional context
The equivalent using Rasterio:
importrasterio# URL to an S3 bucket raster files3_url='s3://your-bucket-name/path-to-your-raster-file.tif'# Open the raster filewithrasterio.open(s3_url) assrc:
# Read a specific band, for example, band 1band1=src.read(1) # Reading only the first band# You can also read multiple specific bands by passing a tupleband1, band3=src.read((1, 3)) # Reading bands 1 and 3# Process or analyze the bands as neededprint(band1, band3)
My current solution:
classSegmentationStreamingDataset(StreamingDataset):
""" Segmentation dataset with streaming. Args: input_dir (str): Local directory or S3 location of the dataset transforms (Optional[Callable]): A transform that takes in an image and returns a transformed version. band_indices (Optional[List[int]]): List of band indices to read from the dataset. """def__init__(self, *args, transforms: Optional[Callable] =None, band_indices: Optional[List[int]] =None, **kwargs):
super().__init__(*args, **kwargs)
self.transforms=transformsself.band_indices=band_indicesdef__getitem__(self, index) ->dict:
data=super().__getitem__(index)
image_name=data["name"]
image=data["image"]
mask=data["mask"]
withMemoryFile(image) asmemfile:
withmemfile.open() asdataset:
image=torch.from_numpy(dataset.read()).float()
ifself.band_indices:
image=image[self.band_indices]
withMemoryFile(mask) asmemfile:
withmemfile.open() asdataset:
mask=torch.from_numpy(dataset.read()).long()
sample= {"image": image, "mask": mask, "image_name": image_name}
ifself.transformsisnotNone:
sample=self.transforms(sample)
returnsample
The text was updated successfully, but these errors were encountered:
🚀 Feature
Streaming subsets of channels
Motivation
My geotiff data is typically multispectral and I do experiments using subsets of the channels. I would like to stream only the required channels in order to save bandwidth
Pitch
Select e.g. channels 1,3,5 to stream
Alternatives
I can list the channels as separate files, and then access only those I require
Additional context
The equivalent using Rasterio:
My current solution:
The text was updated successfully, but these errors were encountered: