stepStart = 0 # initial step i = 0 while stepStart < len(samples): stepEnd = stepStart + chunk_size if stepEnd < len(samples): yield i, samples[stepStart:stepEnd], labels[stepStart:stepEnd] i += 1 stepStart = stepEnd net = Network(train_batch_size=64, test_batch_size=500, pooling_scale=2) net.define_inputs( train_samples_shape=(64, image_size, image_size, num_channels), train_labels_shape=(64, num_labels), test_samples_shape=(500, image_size, image_size, num_channels) ) net.add_conv(patch_size=3, in_depth=num_channels, out_depth=16, activation='relu', pooling=False, name='conv1') net.add_conv(patch_size=3, in_depth=16, out_depth=16, activation='relu', pooling=True, name='conv2') net.add_conv(patch_size=3, in_depth=16, out_depth=16, activation='relu', pooling=False, name='conv3') net.add_conv(patch_size=3, in_depth=16, out_depth=16, activation='relu', pooling=True, name='conv4') # 4 = 两次 pooling,每一次缩小为1/2 # 16 = conv4 out_depth net.add_fc(in_num_nodes=(image_size // 4) * (image_size // 4) * 16, out_num_nodes=16, activation='relu', name='fc1') net.add_fc(in_num_nodes=16, out_num_nodes=10, activation='relu', name='fc2') net.define_model() net.run(get_chunk, train_samples, train_labels, test_samples, test_labels) else: raise Exception('main.py:Should Not Be Imported!!! Must Run by "python main.py"')
in_depth=32, out_depth=32, 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"')