Untitled conversation
- User
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
train_path = "./Project_data/train"
def generator(source_path,
folder_list,
batch_size=32,
index_size = 'best',
img_dim = 120,
use_imgnet_means = True):
if type(index_size) == list:
img_idx = index_size
elif index_size == 'best':
img_idx = list(range(7,26,2))#[4,5,6,10,15,27,28,29] #
elif (index_size > 0) & (type(index_size) == int):
img_idx = sorted(random.sample(range(30),index_size))
num_indices = len(img_idx)
y = img_dim
z = img_dim
while True:
t = np.random.permutation(folder_list)
num_batches = int(len(t)/batch_size)
for batch in range(num_batches):
batch_data = np.zeros((batch_size,num_indices,y,z,3))
batch_labels = np.zeros((batch_size,5))
for folder in range(batch_size):
imgs = os.listdir(source_path+'/'+ t[folder + (batch*batch_size)].split(';')[0])
for idx,item in enumerate(img_idx):
image = imread(source_path+'/'+ t[folder + (batch*batch_size)].strip().split(';')[0]+'/'+imgs[item]).astype(np.float32)
# 1400 images are 160 * 120 , to fix aspect ratio maintain squaring
if image.shape[1] == 160:
resized_image = imresize(image[:,20:140,:],(img_dim,img_dim)).astype(np.float32)
else:
resized_image = imresize(image,(img_dim,img_dim)).astype(np.float32)
if use_imgnet_means:
# Using Imagenet Means for Normalization
batch_data[folder,idx,:,:,0] = resized_image[:,:,0] - 104
batch_data[folder,idx,:,:,1] = resized_image[:,:,1] - 117
batch_data[folder,idx,:,:,2] = resized_image[:,:,2] - 123
else:
#Getting mean and std for normalization
mean = resized_image.mean()
std = resized_image.std()
batch_data[folder,idx,:,:,0] = (resized_image[:,:,0] - mean)/std
batch_data[folder,idx,:,:,1] = (resized_image[:,:,1] - mean)/std
batch_data[folder,idx,:,:,2] = (resized_image[:,:,2] - mean)/std
batch_labels[folder, int(t[folder + (batch*batch_size)].strip().split(';')[2])] = 1
yield batch_data, batch_labels
Whats the best way to create augmented data to improve model performance and reduce overfitting? I am using keras as the deep learning library. Feel free to use any addiitonal libraries like albumentations or augmentor. Some Augmentations relevant to the use case.
Here are some ways you can augment the data in your generator function to improve model performance and reduce overfitting when using Keras:
from keras.preprocessing.image import ImageDataGenerator
data_gen = ImageDataGenerator(
rotation_range=30,
width_shift_range=0.1,
height_shift_range=0.1,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True,
vertical_flip=True
)
import albumentations as A
aug = A.Compose([
A.RandomRotate90(),
A.Transpose(),
A.OneOf([A.IAASharpen(),
A.GaussianBlur(),
A.MotionBlur()], p=0.2),
A.OneOf([A.JpegCompression(),
A.Downscale()], p=0.2),
A.OneOf([A.RandomBrightness(),
A.RandomContrast()], p=0.2),
])
Apply augmentations from PIL like sharpness, blur etc as mentioned in your question.
On-the-fly data augmentation - apply random augmentations to each image while yielding batches from generator.
Save augmented images to disk to increase size of training dataset.
Try different combination of augmentations to find the best performing ones.
Apply light augmentations during validation to reduce overfitting.
This should help increase model variability and reduce chances of overfitting.
does this replace the images or adds more training images? I have chosen only specific frames of a video for each gesture . Will that be an issue
Applying augmentation on-the-fly in the generator will not replace or add more images, it will just modify the existing images randomly during each epoch.
Since you have selected specific frames from the videos as training data, augmenting those frames will help without increasing the actual number of images. Some key points:
Augmentations like flips, rotations, shifts etc applied randomly on each frame will introduce variability without changing the content.
Light augmentations like blur, sharpness changes may slightly modify the content but should still represent the same gesture.
Advanced augmentations from albumentations could potentially modify content more, so use them judiciously.
Ensure the augmentations don't distort the gesture beyond recognition for the model.
Validating on original non-augmented frames prevents overfitting to augmented versions.
So in summary:
Augmentations modify existing frames, don't replace or add more frames.
Should help with limited training frames by introducing variability.
Control augmentations strength to avoid distorting gesture content.
Validating on original data prevents overfitting augmented versions.
With proper augmentation, you should be able to train effectively even with limited frames selected per gesture from videos. Let me know if any part needs more clarification!