Here is an example on how to use an already trained convolutional neural network to evaluate and select the best image according to the training received. In this example the network has been trained to select the best rotation axis centered reconstruction. The test consists of asking the network to select the best centered images coming from a similar sample collected on a different tomographic beamline.

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

To run this example please download the test data from the classify_evaluate folder at url

import dxchange
import numpy as np
from xlearn.utils import nor_data
from xlearn.utils import extract_3d
from xlearn.utils import img_window
from xlearn.classify import model
import matplotlib.pyplot as plt
import time
import glob
Using Theano backend.
Using gpu device 0: Tesla M2050 (CNMeM is disabled, cuDNN not available)

dim_img = 128
patch_size = (dim_img, dim_img)
batch_size = 50
nb_classes = 2
nb_epoch = 12

number of convolutional filters to use

nb_filters = 32

size of pooling area for max pooling

nb_pool = 2

convolution kernel size

nb_conv = 3

Please download the test data from the classify_evaluate folder at


and put them in the test_data folder

nb_evl = 100
fnames = glob.glob('../../test/test_data/*.tiff')
fnames = np.sort(fnames)
mdl = model(dim_img, nb_filters, nb_conv, nb_classes)


Y_score = np.zeros((len(fnames)))
for i in range(len(fnames)):
    img = dxchange.read_tiff(fnames[i])
    img = nor_data(img)
    X_evl = np.zeros((nb_evl, dim_img, dim_img))

    for j in range(nb_evl):
        X_evl[j] = img_window(img[360:1460, 440:1440], dim_img)
    X_evl = X_evl.reshape(X_evl.shape[0], 1, dim_img, dim_img)
    Y_evl = mdl.predict(X_evl, batch_size=batch_size)
    Y_score[i] = sum(np.dot(Y_evl, [0, 1]))
ind_max = np.argmax(Y_score)
print('The well-centered reconstruction is:', fnames[ind_max])
('The well-centered reconstruction is:', '../../test/test_data/1023.00.tiff')