<jupyter_start><jupyter_text>Testing FineNetCode for FineNet in paper "Robust Minutiae Extractor: Integrating Deep Networks and Fingerprint Domain Knowledge" at ICB 2018: https://arxiv.org/pdf/1712.09401.pdfIf you use whole or partial function in this code, please cite paper:    @inproceedings{Nguyen_MinutiaeNet,	author    = {<NAME> and <NAME> and <NAME>},	title     = {Robust Minutiae Extractor: Integrating Deep Networks and Fingerprint Domain Knowledge},	booktitle = {The 11th International Conference on Biometrics, 2018},	year      = {2018},	}<jupyter_code>import sys,os
sys.path.append(os.path.realpath('../FineNet'))
import FineNet_model
from FineNet_model import FineNetmodel, plot_confusion_matrix

import numpy as np
import os
import matplotlib.pyplot as plt
from sklearn.metrics import confusion_matrix
from keras.preprocessing.image import ImageDataGenerator
from keras.optimizers import Adam

os.environ["CUDA_VISIBLE_DEVICES"] = '7'
os.environ['KERAS_BACKEND'] = 'tensorflow'



# ============= Hyperparameters ===============
batch_size = 32
num_classes = 2
path_to_model = '../Models/FineNet.h5'
input_shape = (224, 224, 3)
# ============= end Hyperparameters ===============


# =============== DATA loading ========================
test_path = '../Dataset/test/'

# Feed data from directory into batches
test_gen = ImageDataGenerator()
test_batches = test_gen.flow_from_directory(test_path, target_size=(input_shape[0], input_shape[1]), classes=['minu', 'non_minu'], batch_size=batch_size, shuffle=False)
# =============== end DATA loading ========================


#============== Define model ==================
model = FineNetmodel(num_classes = num_classes,
                     pretrained_path = path_to_model,
                     input_shape = input_shape)

model.compile(loss='categorical_crossentropy',
              optimizer=Adam(lr=0),
              metrics=['accuracy'])
#============== End define model ==============
score = model.evaluate_generator(test_batches)
print 'Test accuracy:', score[1]

test_labels = test_batches.classes[test_batches.index_array]
# ============= Plot confusion matrix ==================

predictions = model.predict_generator(test_batches)

cm = confusion_matrix(test_labels, np.argmax(predictions,axis=1))
cm_plot_labels = ['minu','non_minu']
plot_confusion_matrix(cm, cm_plot_labels, title='Confusion Matrix')<jupyter_output>Test accuracy: 0.950549450549
Confusion matrix, without normalization
[[78  6]
 [ 3 95]]<jupyter_text>Example predicting each patchNote: FineNet works correctly with 'nearest' setting in resize function<jupyter_code># # Can use this
# from keras.preprocessing.image import load_img
# image = load_img('../Dataset/samples/m2.jpg',target_size=(224,224))

# or this
import cv2

image = cv2.imread('../Dataset/samples/m2.jpg')
image = cv2.resize(image, dsize=(224, 224),interpolation=cv2.INTER_NEAREST)
image = np.expand_dims(image, axis=0)

[class_idx] = np.argmax(model.predict(image),axis=1)
print class_idx
print test_batches.class_indices<jupyter_output>0
{'minu': 0, 'non_minu': 1}
{'fraction_non_alphanumeric': 0.17268292682926828, 'fraction_numerical': 0.02666666666666667, 'mean_word_length': 6.006833712984054, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '570639', 'license': 'MIT', 'n_tokens_mistral': 1038, 'n_tokens_neox': 945, 'n_words': 223, 'path': 'Demo_notebooks/demo_FineNet.ipynb', 'repo_name': 'jakubarendac/MinutiaeNet', 'size': '3092'}