GreNait / technical-thesis

This thesis contains all the work related to it. Python code, models, documentation etc.
0 stars 0 forks source link

First image augmentation module #6

Open GreNait opened 4 years ago

GreNait commented 4 years ago
GreNait commented 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/

GreNait commented 4 years ago

I can now turn, rotate, and move image easiyl.

image

GreNait commented 4 years ago

image

GreNait commented 4 years ago

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....

image

image

GreNait commented 4 years ago

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.

GreNait commented 4 years ago

https://www.tensorflow.org/api_docs/python/tf/image <- Describes different parameters to work with tf.image for augmentatioen -> appearently no gaussian noise

GreNait commented 4 years ago

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')

image

GreNait commented 4 years ago

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.

GreNait commented 4 years ago

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

GreNait commented 4 years ago

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

GreNait commented 4 years ago

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.

image

GreNait commented 4 years ago

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

GreNait commented 4 years ago

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.

GreNait commented 4 years ago

Because the ImageDatGenerator appears to work, I will start with the second model using this image data generator for training it.

GreNait commented 4 years ago

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.

GreNait commented 4 years ago

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.

GreNait commented 4 years ago

Using symlinks with a temporary directory sounds like a good idea

GreNait commented 4 years ago

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:

https://stackoverflow.com/questions/42443936/keras-split-train-test-set-when-using-imagedatagenerator

GreNait commented 4 years ago

Splitting the data with the image data generator works perfectly!

GreNait commented 4 years ago

Cleaning the image from the stepper motor works with numpy manipulation.

image

GreNait commented 4 years ago

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]])

image

GreNait commented 4 years ago

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.