In [1]:
import neukrill_net.utils
import PIL.Image
import skimage.transform
In [6]:
%matplotlib inline
import matplotlib.pyplot as plt
In [3]:
cd ..
Doing what the train.py
script does to load images. First loads a the settings into its own object.
In [5]:
settings = neukrill_net.utils.Settings("settings.json")
Then get the dictionary of all the images:
In [12]:
c = next(iter(settings.image_fnames['train'].keys()))
example = settings.image_fnames['train'][c][0]
In [19]:
from IPython.display import display
from IPython.display import Image
from IPython.display import HTML
import matplotlib.cm as cm
In [16]:
e = Image(example)
display(e)
In [17]:
example_array = skimage.io.imread(example)
In [21]:
plt.imshow(example_array, cmap=cm.Greys_r)
Out[21]:
Interesting, so the cropping applied to the data is unreliable. We're going to need that cropping data augmentation. Should get an idea of how much cropping should be applied by these images where the plankton overlaps the edges. Should search the data for these examples before working on that.
In [32]:
import skimage.util
In [49]:
d = abs(example_array.shape[1]-example_array.shape[0])
if d%2 > 0:
x = 1
d = int((d-1)/2)
else:
x = 0
d = int(d/2)
if example_array.shape[1] > example_array.shape[0]:
t = skimage.util.pad(example_array,((d,d+x),(0,0)), 'edge')
else:
t = skimage.util.pad(example_array,((0,0),(d+x,d)), 'edge')
print(t.shape)
plt.imshow(t, cmap=cm.Greys_r)
Out[49]:
In [44]:
r = skimage.transform.resize(t,(48,48))
plt.imshow(r, cmap=cm.Greys_r)
Out[44]:
Have now written this into the augmentation wrapper. Testing this out here:
In [67]:
import neukrill_net.augment
In [72]:
augment_settings = {"rotate":10,"resize":(20,20)}
processing = neukrill_net.augment.augmentation_wrapper(augment_settings)
In [83]:
import imp
In [93]:
imp.reload(neukrill_net.image_processing)
Out[93]:
In [94]:
imp.reload(neukrill_net.augment)
Out[94]:
In [95]:
processed = processing(example_array)
In [96]:
for ea in processed:
print(ea.shape)
plt.imshow(ea, cmap=cm.Greys_r)
plt.show()
Looks like that's working now.
In [97]:
x = np.ones((2,2))
In [101]:
x - 2*np.mean(x)
Out[101]: