예제 #1
0
from neon.frontend import UniformInit, Rectlin, Softmax, GradientDescentMomentum
from neon.frontend import ax, loop_train, make_bound_computation, make_default_callbacks
from neon.frontend import NeonArgparser
from neon.frontend import ArrayIterator

from neon.frontend import CIFAR10
import neon.transformers as ngt

parser = NeonArgparser(description='Train simple mlp on cifar10 dataset')
args = parser.parse_args()

np.random.seed(args.rng_seed)

# Create the dataloader
train_data, valid_data = CIFAR10(args.data_dir).load_data()
train_set = ArrayIterator(train_data, args.batch_size, total_iterations=args.num_iterations)
valid_set = ArrayIterator(valid_data, args.batch_size)

inputs = train_set.make_placeholders()
ax.Y.length = 10

######################
# Model specification


def cifar_mean_subtract(x):
    bgr_mean = ng.persistent_tensor(
        axes=x.axes.find_by_name('C'),
        initial_value=np.array([104., 119., 127.]))
    return (x - bgr_mean) / 255.
예제 #2
0
image_size = 224
X_train = np.random.uniform(-1, 1,
                            (args.batch_size, 3, image_size, image_size))
y_train = np.ones(shape=(args.batch_size), dtype=np.int32)
train_data = {
    'image': {
        'data': X_train,
        'axes': ('N', 'C', 'H', 'W')
    },
    'label': {
        'data': y_train,
        'axes': ('N', )
    }
}
train_set = ArrayIterator(train_data,
                          batch_size=args.batch_size,
                          total_iterations=args.num_iterations)
inputs = train_set.make_placeholders(include_iteration=True)
ax.Y.length = 1000  # number of outputs of last layer.

# weight initialization
bias_init = UniformInit(low=-0.08, high=0.08)


class Inception(Sequential):
    def __init__(self,
                 branch_units,
                 activation=Rectlin(),
                 bias_init=UniformInit(low=-0.08, high=0.08),
                 filter_init=XavierInit()):
예제 #3
0
# Generate Lissajous Curve
data = timeseries.TimeSeries(
    train_ratio=0.8,  # ratio of samples to set aside for training
    seq_len=seq_len,  # length of the sequence in each sample
    npoints=no_points,  # number of points to take in each cycle
    ncycles=no_cycles,  # number of cycles in the curve
    batch_size=batch_size,
    curvetype='Lissajous2',
    predict_seq=predict_seq,  # set True if you want sequences as output
    look_ahead=look_ahead)  # number of time steps to look ahead

# Build input data iterables
# Yields an input array of Shape (batch_size, seq_len, input_feature_dim)
num_iterations = no_epochs * no_batches
train_set = ArrayIterator(data.train,
                          batch_size,
                          total_iterations=num_iterations)
test_set = ArrayIterator(data.test, batch_size)

# Name and create axes
batch_axis = ng.make_axis(length=batch_size, name="N")
time_axis = ng.make_axis(length=seq_len, name="REC")
feature_axis = ng.make_axis(length=feature_dim, name="feature_axis")
out_axis = ng.make_axis(length=output_dim, name="output_axis")

in_axes = ng.make_axes([batch_axis, time_axis, feature_axis])
if (predict_seq is True):
    out_axes = ng.make_axes([batch_axis, time_axis, out_axis])
else:
    out_axes = ng.make_axes([batch_axis, out_axis])