Exemple #1
0
import pandas as pd
from sklearn.preprocessing import MinMaxScaler
from dbn import SupervisedDBNClassification, SupervisedDBNRegression
from sklearn.metrics import confusion_matrix
from sklearn.model_selection import train_test_split
import numpy as np
import tensorflow as tf
from PIL import Image

path_url = sys.argv[1]
path1 = ('ImagesPredict//' + path_url)
image = Image.open(path1).convert('L').resize((100, 100))
img = np.asarray(image)
img = img.astype('float32')
img /= 255.0
path = 'dbntrained_255_24_hum_94.pkl'
classifier = SupervisedDBNClassification.load(path)
y = list()
y.append(img)
y = np.array(y)
y = y.reshape(-1, 100 * 100)
Y_pred = classifier.predict(y)
# print(Y_pred[0]) #0-> normal 1-> pneumonie
if (Y_pred[0] == 0):
    print("Absence de signe de pneumonie.")
elif (Y_pred[0] == 1):
    print("Attention presence d'une pneumonie mogene !")
else:
    print("veillez inserer une image correct !")

Exemple #2
0
# Data scaling
X = (X / 16).astype(np.float32)

# Splitting data
X_train, X_test, Y_train, Y_test = train_test_split(X,
                                                    Y,
                                                    test_size=0.2,
                                                    random_state=0)

# Training
classifier = SupervisedDBNClassification(
    hidden_layers_structure=[1000, 1000, 1000],
    learning_rate_rbm=0.05,
    learning_rate=0.1,
    n_epochs_rbm=15,
    n_iter_backprop=50,
    batch_size=32,
    activation_function='relu',
    dropout_p=0.2)
classifier.fit(X_train, Y_train)

# Save the model
classifier.save('model.pkl')

# Restore it
classifier = SupervisedDBNClassification.load('model.pkl')

# Test
Y_pred = classifier.predict(X_test)
print 'Done.\nAccuracy: %f' % accuracy_score(Y_test, Y_pred)