Esempio n. 1
0
from data_load import load_CIFAR10
#from theano import function, config, shared, sandbox
#import theano.tensor as T

#
# from setup_GPU import setup_theano
#
# setup_theano()

from lasagne import layers
from lasagne.updates import nesterov_momentum
from lasagne.nonlinearities import softmax
from nolearn.lasagne import NeuralNet

cifar10_dir = "/home/kel/cifar-10-batches-py"
X_train, y_train, X_test, y_test = load_CIFAR10(cifar10_dir)

X_train_2d = np.dot(X_train[..., :3],
                    [0.299, 0.587, 0.114]).reshape(-1, 1, 32,
                                                   32).astype(np.float32)
X_test_2d = np.dot(X_test[..., :3],
                   [0.299, 0.587, 0.114]).reshape(-1, 1, 32,
                                                  32).astype(np.float32)

X_train_2d = (X_train_2d / 255.0) - 0.5
X_test_2d = (X_test_2d / 255.0) - 0.5

net2 = NeuralNet(
    layers=[
        ('input', layers.InputLayer),
        ('conv1', layers.Conv2DLayer),
Esempio n. 2
0
import tensorflow as tf
import numpy as np
import pandas as pd
import random
from data_load import load_CIFAR10
import matplotlib.pyplot as plt
from knn import knn

plt.rcParams['figure.figsize'] = (10, 8)
plt.rcParams['image.interpolation'] = 'nearest'
plt.rcParams['image.cmap'] = 'gray'

filepath = 'data/cifar-10-batches-py'
X_train, y_train, X_test, y_test = load_CIFAR10(filepath)

print('train data shape:', X_train.shape)
print('train labels shape:', y_train.shape)
print('test data shape:', X_test.shape)
print('test labels shape:', y_test.shape)

#########显示部分数据集
classes = [
    'plane', 'car', 'bird', 'cat', 'deer', 'dog', 'drog', 'horse', 'ship',
    'truck'
]
num_classes = len(classes)
samples_per_class = 7
for y, cls in enumerate(classes):
    idxs = np.flatnonzero(y_train == y)
    idxs = np.random.choice(idxs, samples_per_class, replace=False)
    for i, idx in enumerate(idxs):
Esempio n. 3
0
cbs_gauss_kmeans = [m.EarlyStopping(monitor='val_loss', patience=patience), 
                    m.ModelCheckpoint(model_name_gauss_kmeans, monitor='val_loss', 
                    verbose=0, save_best_only=True, mode='min')]

cbs_gauss_kmedoids = [m.EarlyStopping(monitor='val_loss', patience=patience), 
                        m.ModelCheckpoint(model_name_gauss_kmedoids, monitor='val_loss', 
                        verbose=0, save_best_only=True, mode='min')]

cbs_gauss_no_init = [m.EarlyStopping(monitor='val_loss', patience=patience), 
                        m.ModelCheckpoint(model_name_gauss_no_init, monitor='val_loss', 
                        verbose=0, save_best_only=True, mode='min')]

# Dataset Setup

if dataset == "CIFAR-10":
    x_train, x_test, y_train, y_test = adl.load_CIFAR10()
    n_classes = 10
else:
    x_train, x_test, y_train, y_test = adl.load_CIFAR100()
    n_classes = 100

x_train_pct, y_train_pct = m.sample_train(x_train, y_train, train_pct)
m.print_params(feature_extractor, embedding_dim, n_centers_per_class, n_classes, 
                lr, sigma, batch_size, epochs, dataset, input_shape, patience)


# Training Models

''' Softmax Model / Plain Model.
    Without Initialization.
    With Inverse Kernel.