Ejemplo n.º 1
0
import sys

sys.path.append("../..")

import lab0.src.dataset8 as dataset8
from sklearn import metrics
from neupy import algorithms
import numpy as np

from lib.image import noise, get_pxs

print(
    "\n\nИсследуем качество классификации на тестовой выборке содержащей зашумленные примеры"
)

(x_train, y_train), (x_test, y_test) = dataset8.load_data(mode=0)

pnn = algorithms.PNN(std=1, batch_size=128, verbose=False)

pnn.train(x_train[0:10000], y_train[0:10000])

y_predicted = pnn.predict(x_test)

local_path = 'my_images/'
for nTest in np.arange(0, 10, 1):
    # convert to numpy array
    x = get_pxs(local_path + str(nTest) + '.png')

    # Inverting and normalizing image
    x = 255 - x
    x /= 255
Ejemplo n.º 2
0
    # 1,2 initializing
    batch_size = 32
    num_classes = 10
    epochs = 10
    lr = 0.01
    verbose = 1
    neurons_number = [256, num_classes]

    opt_name = "Adam"
    optimizer = Adam()

    goal_loss = 0.013

    (x_train, y_train), (x_test,
                         y_test) = dataset8.load_data(mode=2,
                                                      show=True,
                                                      show_indexes=[0, 1])

    model = Sequential()

    model.add(Dense(neurons_number[0], input_dim=28**2, activation='relu'))

    model.add(Dense(neurons_number[1], activation='softmax'))

    # 3 setting stopper
    callbacks = [
        EarlyStoppingByLossVal(monitor='val_loss', value=goal_loss, verbose=1)
    ]

    # 4 model fitting
    model.compile(optimizer=optimizer,