# ML Homework 2 Report
### By Miklashevskaya Daria, DS-02
In this homework, we were given German Traffic Sign Dataset for multi-class classification. The pictures should be classified according to the traffic signs they represent.
## Results of padding
- Original version

- Padded version

- The type of padding I used here is replication of the borders. As one can see, my algorithm adds padding to the upper and bottom sides of the picture. Three rows needs to be inserted, so one was inserted in the top part and two -- in the bottom part. This was done to avoid shifting the picture too much.
## Bar chart of class frequencies
- Before augmentation

- After augmentation

In my implementation, I tried completing the set by defining the maximum of all the counts and by using a fixed limit. Using a fixed and large limit gave slight improvements in terms of accuracy.
## Justification of augmentation choice
- Since we compare values of pixels, shifting and rotating the image may be a challenge for classifying such images. Besides, it is not so common in the real world. I used settings of brightsness, gaussian noise, which represent the conditions that can be met in the real life, such as sunshine or random noise due to poor quality of the equipment/precipitation.
## Examples of augmentation
- In my algorithms, I used the library 'albumentations' for data augmentation. Among many filters that I tried, I stopped on the following:
- ToGray
- I was trying to include grey images, so that the model would not only look at the colors to identify the sign, but the edges and the shape of the object
- HueSaturationValue
- this corresponds to different levels of saturation throughout the day, which allows to artificially create such conditions as day and night (example below)
- RGBShift
- rotate the color channel. I used it so that the model would not be confused by different colors that depends on the conditions and time of the day
- RandomBrightness
- the amount of light as in natural conditions
- RandomContrast
- the amount of contrast that can be dependent from device to device
- GaussNoise
- noise is necessary, because of bad capabilities of equipment to shoot at night or when it's getting dark (artificial obstacles for the model)
- Posterize
- I decided to try posterization because it usually captures the essence of the image, smoothing all unneccessary detail
- All of these filters were applied with probability 0.5, so during each run, only a portion of them was applied to a picture, making the dataset (and artificial conditions) more diverse. Below are the results of some of them.






- After trying out some tricks with rotation/scaling and flipping, I decided to exclude those filters, because the accuracy of the model was going down. Most probably, it was happenning because of comparing the pixels and thus high sensitivity to scaling/shifting (it is hard for this model to detect these transformation)
## Estimates

- These are precision and recall based on mean averaging. Below you can find precision and recall for each class (for each of the five sizes of images).
## Incorrectly classified samples




- It is obvous that the most challenging images for the model are those that are too blurred, not bright enought and overall the distribution of the pixel on the banner does not give any hints about which label it is. This can happen because of either bad filtering during the augmentation stage, resizing images to smaller dimensions (llosing information) or bad quality of pictures. Also, the model is often mistaken with symbols that are very similar, such as 50, 30 and 80.
## Comparison with training on non-augmented data
- Models performcance

- Effect of augmentation
- Augmentation can improve the precision of the model by introducing variability. However, those transformations should be carefully chosen.
- The performance of the model actually depends on the augmentation chosen quite a lot, especially when a lot of new images are introduced. If the transformations are very slight, then the new images are not that different from the original ones and then they are the same as adding more weight to some picture, which makes the dataset unbalanced. If the filters are applied in a very harsh manner, then many outliers can exist, such as completely black/white squares; images, where nothing can be seen, etc -- faulty data, which is an obstacle for good-quality training and results in bad classification results.
## Changing the size
- Models performance
- 5 different size options
- size=10
- 
- size=15
- 
- size=20
- 
- size=25
- 
- size=35
- 
As it can be seen, in my example accuracy increases with increase in the size
# How accuracy and time depend on image size
- For this task, I made a dataframe so it would be more convenient to look at the results

- how accuracy depends on image size

- how time depends on image size

- It can be seen, that as the size of the image increases, the time it takes for the algorithm to complete grows linearly and the accuracy is also dependant on the image size -- in general, the larger the image -- the better the results (because it conveys more information, and when we resize large images to small, we loose this valuable information).