PredictΒΆ

Here is an example on how to use an already trained convolutional neural network to automatically segment a series of raw images.

You can download the python scritp here or the Jupyter notebook here

%pylab inline
Populating the interactive namespace from numpy and matplotlib
import dxchange

Image data I/O in xlearn is supported by DXchange.

import matplotlib.pyplot as plt

matplotlib provide plotting of the result in this notebook.

Install xlearn then:

from xlearn.transform import model
from xlearn.transform import predict
batch_size = 800
nb_epoch = 40
dim_img = 20
nb_filters = 32
nb_conv = 3
patch_step = 4

patch_size = (dim_img, dim_img)
mdl = model(dim_img, nb_filters, nb_conv)
mdl.load_weights('training_weights.h5')
fname = '../../test/test_data/predict_test.tiff'
img_test = dxchange.read_tiff(fname)
plt.imshow(img_test, cmap='Greys_r')
plt.show()
../../_images/predict_4_0.png
fname_save = '../../test/test_data/predict_test_result'
img_rec = predict(mdl, img_test, patch_size, patch_step, batch_size, dim_img)
dxchange.write_tiff(img_rec, fname_save, dtype='float32')
plt.imshow(img_rec, cmap='Greys_r')
plt.show()
../../_images/predict_8_0.png