The word “hacking” could be different meaning for different people, some might said that it refers to “studying the network to the every single pieces”, some might said it means cracking the network to do something good or bad.
For this article, “Hacking Deep Learning Network” could mean “Cheating DNN”. Whichever terms used, they are just to make something simple looks complicated and make some loud noises on the articles, including this. 🙂
To be more exact, we want to try how a DNN could stand on the correct answer/prediction with different level of noise, and how to overcome this. We will use Google Vision API for this purpose.
Consider the following original image, which we could see in most article on deep learning articles:
Trying to get Google Vision API to label this gives:
Great, the engine is 99% sure it is a cat!
Let’s add some salt and pepper noise (10%) to the image with the following code:
S = imread('cat.jpg'); Sn = imnoise(S,'salt & pepper',0.1); imwrite(Sn,'cat_n10.jpg');
and uploading to the Google Vision API gives:
Not bad, it still could give the prediction in high level of confident!
Now, let’s try 25% noise:
and the result:
ok, the “Cat” dropped to 91% and others overtook its’ place.
The previous 2 examples were added noise randomly for each layers, that’s the reason you could see the “salts” are the mix of red, blue and green.
Let’s try to add the same noise to all 3 layers (Following codes would be added into “imnoise” function in future release):
S = imread('cat.jpg'); N = uint8(100.*ones(300,400)); N2 = imnoise(N,'salt and pepper',0.1); ind1 = find(N2==0); ind2 = find(N2==255); S(ind1) = 0; prod(size(N)) S(ind1+prod(size(N))) = 0; S(ind1+prod(size(N))*2) = 0; S(ind2) = 255; S(ind2+prod(size(N))) = 255; S(ind2+prod(size(N))*2) = 255;
The image looks less noisy than the previous one, however:
Now let’s see how to solve this by using median filter and averaging filter:
I = immedian(S,3); imwrite(I,'cat_med.jpg'); F = fspecial('average',9); I2 = imfilter(S,F); imwrite(I2,'cat_ave9.jpg');
and the results:
Output of median filter:
Output of averaging filter with filter size of 9×9
and the result:
It looks like even the output of the averaging filter is a bit “blur” for human eye, Google Vision API might sees it differently.
Perhaps next time if you want to get better result for your image, you should pass the image through the averaging filter first, whether or not it is corrupted by noise.
You could try it out with the original image passing through the averaging filter and you know what I mean.