Пример #1
0
def train(request):
    print("begin")
    training_data, validation_data, test_data = mnl.load_data_wrapper()
    print("loaded ... starting training")
    ar,steps = net.SGD(training_data, 4, 10, 3.0, test_data=test_data)
    data = {'error':ar,'batch':steps}
    return JsonResponse(data)
import network.network as Network
import network.mnist_loader as mnist_loader
import pickle
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d, Axes3D
import numpy as np
from ripser import ripser
from persim import plot_diagrams

with open('network/trained_network.pkl', 'rb') as f:
    u = pickle._Unpickler(f)
    u.encoding = 'latin1'
    net = u.load()

train_data, train_labels, test_data, test_labels = mnist_loader.load_data_wrapper(
)


def predict(n):
    # Get the data from the test set
    x = test_data[n]

    # Print the prediction of the network
    print('Network output: \n' + str(np.round(net.feedforward(x), 2)) + '\n')
    print('Network prediction: ' + str(np.argmax(net.feedforward(x))) + '\n')
    print('Actual image: ')

    # Draw the image
    plt.figure()
    plt.imshow(x.reshape((28, 28)), cmap='Greys')
    plt.show()
Пример #3
0
import matplotlib.pyplot as plt
import numpy as np


#with open('network/trained_network.pkl', 'rb') as f:
 #   net = cPickle.load(f, encoding = 'latin1')

# PYTHON 3 WORK AROUND (uncomment this
# and comment the above if using python 3)
with open('network/trained_network.pkl', 'rb') as f:
    u = pickle._Unpickler(f)
    u.encoding = 'latin1'
    net = u.load()
    #net = cPickle.load(f, encoding = 'latin1')
    
training_data, validation_data, test_data = mnist_loader.load_data_wrapper()

def predict(n):
    # Get the data from the test set
    x = test_data[n][0]

    # Print the prediction of the network
    print('Network output: \n' + str(np.round(net.feedforward(x), 2)) + '\n')
    print('Network prediction: ' + str(np.argmax(net.feedforward(x))) + '\n')
    print('Actual image: ')
    
    # Draw the image
    plt.imshow(x.reshape((28,28)), cmap='Greys')

# Replace the argument with any number between 0 and 9999
#predict(8384