Comments (1)
Doing data augmentation inside the library needs more effort and it add more dependencies to the library. As of this day, I am thinking to use imgaug
as a data augmentation. If I add this library, the following dependencies will be added to the code,
- Scipy
- Matplotlib
- scikit-image
- imageio
- imgaug
So, for now, I am thinking not to include data augmentation. But if anyone wants to use the data augmentation, you can do as below using imgaug
library.
import imgaug.augmenters as iaa
from imgaug.augmentables.segmaps import SegmentationMapsOnImage
import numpy as np
# Define augmentation pipeline
seq = iaa.Sequential([
iaa.Fliplr(0.5), # Horizontal flip
iaa.Flipud(0.5), # Vertical flip
iaa.Affine(rotate=(-45, 45)), # Random rotation between -45 and 45 degrees
iaa.Affine(scale=(0.5, 1.5)), # Random scaling between 0.5x and 1.5x
iaa.Affine(translate_percent={"x": (-0.2, 0.2), "y": (-0.2, 0.2)}), # Random translation
# iaa.AdditiveGaussianNoise(scale=(0, 0.05*255)), # Gaussian noise
# iaa.ElasticTransformation(alpha=50, sigma=5) # Elastic deformation
])
# Apply augmentation to images and masks
augmented_images, augmented_masks = seq(images=TRAIN_XX, segmentation_maps=TRAIN_YY)
In above code, the TRAIN_XX shape(num_tiles, x, y, bands)
and TRAIN_YY shape(num_tiles, x, y, 1)
. The above code will only generate the 1 set of augmentation, i.e. if your total number of tiles is 10, then it will only generate 10 additional tiles.
But in order to generate more number of tiles, you can do as below,
augmented_images = []
augmented_masks = []
num_augmentations = 15 # total number of tiles will be: num_augmentations * number of features
# Apply augmentation to each original image and mask
for i in range(TRAIN_XX.shape[0]):
image = TRAIN_XX[i]
mask = TRAIN_YY[i]
# Create a segmentation map object from the mask
segmentation_map = SegmentationMapsOnImage(mask, shape=image.shape)
# Apply augmentation num_augmentations times
for _ in range(num_augmentations):
# Apply the same augmentation to both image and mask
augmented_image, augmented_segmentation_mask = seq.augment(image=image, segmentation_maps=segmentation_map)
# Append the augmented image and mask to the lists
augmented_images.append(augmented_image)
augmented_masks.append(augmented_segmentation_mask.get_arr())
# Convert lists to numpy arrays
augmented_images = np.array(augmented_images)
augmented_masks = np.array(augmented_masks)
# append augmented images/masks with original images/masks
all_images = np.concatenate((TRAIN_XX, augmented_images), axis=0)
all_masks = np.concatenate((TRAIN_YY, augmented_masks), axis=0)
from geotile.
Related Issues (20)
- Mask function generating RGB image instead of single band image. HOT 1
- Data normalization HOT 1
- Need to write function to create the numpy array
- Need function to construct the single prediction raster from tiles HOT 1
- Need function to get the info about tiles
- Auto API document is not working! HOT 1
- naming the tiles based on custom format
- Rasterization issue: ValueError: Given nodata value, nan, is beyond the valid range of its data type, uint8.
- MemoryError: Unable to allocate ... GiB for an array with shape (num_features, 256, 256, 4) and data type `float64` HOT 1
- `gt.merge_tiles` method is not working as expected! HOT 3
- Fiona is not defined error in vectorize
- Need to optimize the generate_tiles function.
- gt.save_tile have issue
- mosaic raster issue: Bounds and transform are inconsistent HOT 4
- Filter the vectorize values based on the filter conditon
- `gt.save_tiles` issue: TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
- Data normalization based on z-score HOT 1
- Given nodata value, -32768.0, is beyond the valid range of its data type, uint8.
- Need function to Convert no data value to zero values
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from geotile.