layer_params = layer.get_params(trainable=True) if name in ['new_output', 'fc6', 'fc7']: layer_lr = learning_rate else: layer_lr = learning_rate / 10 if name != 'fc8': layer_updates = lasagne.updates.nesterov_momentum( loss, layer_params, learning_rate=layer_lr, momentum=0.9) updates.update(layer_updates) # Compile functions for training, validation and prediction train_fn = theano.function([X_sym, y_sym], [loss, acc], updates=updates) val_fn = theano.function([X_sym, y_sym], [loss, acc]) pred_fn = theano.function([X_sym], prediction) X_train, y_train, ids_train = load_train_data() X_test, ids_test = load_test_data(img_start_ix=0, max_img=1000) y_pseudo = load_pseudo_labels() pos = np.array(range(4777)) X, y, ids = np.concatenate((X_train, X_test)), np.concatenate( (y_train, y_pseudo)), np.concatenate((ids_train, ids_test)) X, y, ids, pos = sklearn.utils.shuffle(X, y, ids, pos, random_state=0) new_pseudo_label_pos = [] for i in range(3777, 4777): k = np.where(pos == i) new_pseudo_label_pos.append(int(k[0])) # generator splitting an iterable into chunks of maximum length N def batches(iterable, N):
for name, layer in net.items(): layer_params = layer.get_params(trainable=True) if name in ['new_output', 'fc6', 'fc7']: layer_lr = learning_rate else: layer_lr = learning_rate / 10 if name != 'fc8': layer_updates = lasagne.updates.nesterov_momentum(loss, layer_params, learning_rate=layer_lr, momentum=0.9) updates.update(layer_updates) # Compile functions for training, validation and prediction train_fn = theano.function([X_sym, y_sym], [loss, acc], updates=updates) val_fn = theano.function([X_sym, y_sym], [loss, acc]) pred_fn = theano.function([X_sym], prediction) X, y, ids = load_train_data() X, y, ids = sklearn.utils.shuffle(X, y, ids, random_state=0) # generator splitting an iterable into chunks of maximum length N def batches(iterable, N): chunk = [] for item in iterable: chunk.append(item) if len(chunk) == N: yield chunk chunk = [] if chunk: yield chunk # We need a fairly small batch size to fit a large network like this in GPU memory BATCH_SIZE = 12