Open GreNait opened 4 years ago
I used this side to gget some idea on how to augment my images:
https://debuggercafe.com/image-transformation-using-opencv-and-python/
I can now turn, rotate, and move image easiyl.
To fill the black pixels, we need to define the fill_mode as "constant" and provide a cval value with the pixel value.
....fill_mode= "constant",cval=255....
Gaussian Noise example: https://machinelearningmastery.com/how-to-improve-deep-learning-model-robustness-by-adding-noise/
-> It might also make sense, too add a bit of nboise before an activation funtion inside a model fit.
https://www.tensorflow.org/api_docs/python/tf/image <- Describes different parameters to work with tf.image for augmentatioen -> appearently no gaussian noise
I am trying to add noise to the image, this is harder than expected. I now try a package called scikit perhaps that works.
-> It worked with skimage easiyl (one line of code
noise_img = random_noise(img_array[0], mode='gaussian')
For the documentation, it is better to use augmentation but not save it necessarily. Because you do not want to save all data on the disk and avoid unnecessary memory.
It appears, that the ImageDataGenerator can do even more than only augment. It rescales, normailzes data. It might be unnecessary to use the creatingDataset modul. We will see how this is working out
https://www.tensorflow.org/tutorials/images/classification
This is a sample for image classification, which I am doing. This uses ImageDataGenerator etc. and is a good starting point for the next "model" = model 2 (milestone) after getting used to the ImageDataGenerator and the augmentation with tensorflow 2.1
With the imageDatGeneroatro I was able to iter through all files. No augmentation yet done. This would be the next steps. But I already know, that I need to add nois before the image augmentation via the imageDataGenerator.
I moved the noise adding to the creation of the dataset. Because it is not part of the input pipeline of the image data generator. If adding a noise seed to the model is valid, the noise adding to the image might be unnecessary at all. I shoul also use the dataset creation for generating training and validation sets. Split like 70/30
It appears, that the zoom in function doesn't work well together with the rotation. I skip the zoom and use that maybe later in the technical thesis.
Because the ImageDatGenerator appears to work, I will start with the second model using this image data generator for training it.
In my opinion, the augmetnation works good, but the raw images are not perfect for the training. there are several things to do to improve the image data. Inlcuding better position of the fugres, excluding the sockel/step motor, and always bright background.
Using symlinks with the os.symlink modul appears to be a good idea, so to not copy the same images. Instead, just having a link to that file. But I need to test, if this is working with an image generator.
Using symlinks with a temporary directory sounds like a good idea
Again, the image data generator is a great tool. Instead of splititng the data dn generating symlinks etc. , I can define based on one dataset, also to split hem with the imagedatagenerator. See following stack overflow example:
Splitting the data with the image data generator works perfectly!
Cleaning the image from the stepper motor works with numpy manipulation.
By using a bit of numpy magic, it was also possible to change the color from white to the most used color in the image.
(values, counts) = np.unique(img, return_counts=True) ind=np.argmax(counts)
for i in range(row, len(img)):
img[i] = np.array([values[ind],values[ind],values[ind]])
Adding noise ia also working. I generated now from 1000 images another 2000 images for the training. This should help with the second model a lot for later improvement.