def main(): ValidSampler = Sampler(utils.valid_file) TestSampler = Sampler(utils.test_file) networks = [] weights = [] for i in xrange(5): if i == 0: TrainSampler = Sampler(utils.train_file) prev_ys = np.copy(TrainSampler.labels) else: TrainSampler = Sampler(utils.train_file, prev_ys) network = Network() network.train(TrainSampler) cur_ys = network.predict(TrainSampler) b1 = np.sum(np.multiply(cur_ys, prev_ys)) b2 = np.sum(np.multiply(cur_ys, cur_ys)) w = float(b1) / b2 prev_ys = np.subtract(prev_ys, w * cur_ys) print i, 'done with weight', w network.save('network_' + str(i) + '.ckpt') weights.append(w) networks.append(network) validate_boost(ValidSampler, networks, weights) validate_boost(TestSampler, networks, weights) np.save('weights.npy', weights)
def main(): ValidSampler = Sampler(utils.valid_file) TestSampler = Sampler(utils.test_file) networks = [] weights = [] for i in xrange(5): if i == 0: TrainSampler = Sampler(utils.train_file) prev_ys = np.copy(TrainSampler.labels) else: TrainSampler = Sampler(utils.train_file, prev_ys) network = Network() network.train(TrainSampler) cur_ys = network.predict(TrainSampler) b1 = np.sum(np.multiply(cur_ys, prev_ys)) b2 = np.sum(np.multiply(cur_ys, cur_ys)) w = float(b1) / b2 prev_ys = np.subtract(prev_ys, w * cur_ys) print i, 'done with weight', w network.save('network_' + str(i) + '.ckpt') weights.append(w) networks.append(network) validate_boost(ValidSampler, networks, weights) validate_boost(TestSampler, networks, weights) np.save('weights.npy', weights)
def test(a, b): white = Network(a) black = Network(b) print("training") white.train() print("playing") board = chess.Board() for i in range(10): print(i) board.reset() while not board.is_game_over(): move = play(board, white, True) if board.is_game_over(): break board.push(move) move = play(board, black, False) board.push(move) print(board.result())
activation='relu', pooling=False, name='conv3') net.add_conv(patch_size=3, in_depth=32, out_depth=32, activation='relu', pooling=True, name='conv4') # 4 = 两次 pooling, 每一次缩小为 1/2 # 32 = conv4 out_depth net.add_fc(in_num_nodes=(image_size // 4) * (image_size // 4) * 32, out_num_nodes=128, activation='relu', name='fc1') net.add_fc(in_num_nodes=128, out_num_nodes=10, activation=None, name='fc2') net.define_model() # net.run(train_samples, train_labels, test_samples, test_labels, train_data_iterator=train_data_iterator, # iteration_steps=3000, test_data_iterator=test_data_iterator) net.train(train_samples, train_labels, data_iterator=train_data_iterator, iteration_steps=2000) net.test(test_samples, test_labels, data_iterator=test_data_iterator) else: raise Exception( 'main.py: Should Not Be Imported!!! Must Run by "python main.py"')