我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用tflearn.max_pool_2d()。
def test_feed_dict_no_None(self): X = [[0., 0., 0., 0.], [1., 1., 1., 1.], [0., 0., 1., 0.], [1., 1., 1., 0.]] Y = [[1., 0.], [0., 1.], [1., 0.], [0., 1.]] with tf.Graph().as_default(): g = tflearn.input_data(shape=[None, 4], name="X_in") g = tflearn.reshape(g, new_shape=[-1, 2, 2, 1]) g = tflearn.conv_2d(g, 4, 2) g = tflearn.conv_2d(g, 4, 1) g = tflearn.max_pool_2d(g, 2) g = tflearn.fully_connected(g, 2, activation='softmax') g = tflearn.regression(g, optimizer='sgd', learning_rate=1.) m = tflearn.DNN(g) def do_fit(): m.fit({"X_in": X, 'non_existent': X}, Y, n_epoch=30, snapshot_epoch=False) self.assertRaisesRegexp(Exception, "Feed dict asks for variable named 'non_existent' but no such variable is known to exist", do_fit)
def vgg16(input, num_class): x = tflearn.conv_2d(input, 64, 3, activation='relu', scope='conv1_1') x = tflearn.conv_2d(x, 64, 3, activation='relu', scope='conv1_2') x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool1') x = tflearn.conv_2d(x, 128, 3, activation='relu', scope='conv2_1') x = tflearn.conv_2d(x, 128, 3, activation='relu', scope='conv2_2') x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool2') x = tflearn.conv_2d(x, 256, 3, activation='relu', scope='conv3_1') x = tflearn.conv_2d(x, 256, 3, activation='relu', scope='conv3_2') x = tflearn.conv_2d(x, 256, 3, activation='relu', scope='conv3_3') x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool3') x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv4_1') x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv4_2') x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv4_3') x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool4') x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv5_1') x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv5_2') x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv5_3') x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool5') x = tflearn.fully_connected(x, 4096, activation='relu', scope='fc6') x = tflearn.dropout(x, 0.5, name='dropout1') x = tflearn.fully_connected(x, 4096, activation='relu', scope='fc7') x = tflearn.dropout(x, 0.5, name='dropout2') x = tflearn.fully_connected(x, num_class, activation='softmax', scope='fc8', restore=False) return x
def test_conv_layers(self): X = [[0., 0., 0., 0.], [1., 1., 1., 1.], [0., 0., 1., 0.], [1., 1., 1., 0.]] Y = [[1., 0.], [0., 1.], [1., 0.], [0., 1.]] with tf.Graph().as_default(): g = tflearn.input_data(shape=[None, 4]) g = tflearn.reshape(g, new_shape=[-1, 2, 2, 1]) g = tflearn.conv_2d(g, 4, 2, activation='relu') g = tflearn.max_pool_2d(g, 2) g = tflearn.fully_connected(g, 2, activation='softmax') g = tflearn.regression(g, optimizer='sgd', learning_rate=1.) m = tflearn.DNN(g) m.fit(X, Y, n_epoch=100, snapshot_epoch=False) # TODO: Fix test #self.assertGreater(m.predict([[1., 0., 0., 0.]])[0][0], 0.5) # Bulk Tests with tf.Graph().as_default(): g = tflearn.input_data(shape=[None, 4]) g = tflearn.reshape(g, new_shape=[-1, 2, 2, 1]) g = tflearn.conv_2d(g, 4, 2) g = tflearn.conv_2d(g, 4, 1) g = tflearn.conv_2d_transpose(g, 4, 2, [2, 2]) g = tflearn.max_pool_2d(g, 2)
def generator(input_image): conv2d = tflearn.conv_2d batch_norm = tflearn.batch_normalization relu = tf.nn.relu ratios = [16, 8, 4, 2, 1] n_filter = 8 net = [] for i in range(len(ratios)): net.append(tflearn.max_pool_2d(input_image, ratios[i], ratios[i])) # block_i_0, block_i_1, block_i_2 for block in range(3): ksize = 1 if (block + 1) % 3 == 0 else 3 net[i] = relu(batch_norm(conv2d(net[i], n_filter, ksize))) if i != 0: # concat with net[i-1] upnet = batch_norm(net[i - 1]) downnet = batch_norm(net[i]) net[i] = tf.concat(3, [upnet, downnet]) # block_i_3, block_i_4, block_i_5 for block in range(3, 6): ksize = 1 if (block + 1) % 3 == 0 else 3 net[i] = conv2d(net[i], n_filter * (i + 1), ksize) net[i] = relu(batch_norm(net[i])) if i != len(ratios) - 1: # upsample for concat net[i] = tflearn.upsample_2d(net[i], 2) nn = len(ratios) - 1 output = conv2d(net[nn], 3, 1) return output
def example_net(x): network = tflearn.conv_2d(x, 32, 3, activation='relu') network = tflearn.max_pool_2d(network, 2) network = tflearn.conv_2d(network, 64, 3, activation='relu') network = tflearn.conv_2d(network, 64, 3, activation='relu') network = tflearn.max_pool_2d(network, 2) network = tflearn.fully_connected(network, 512, activation='relu') network = tflearn.dropout(network, 0.5) network = tflearn.fully_connected(network, 3, activation='softmax') return network
def trythisnet(x): network = tflearn.conv_2d(x,64,5,activation='relu') network = tflearn.max_pool_2d(network,3,2) network = tflearn.local_response_normalization(network,4,alpha=0.001/9.0) network = tflearn.conv_2d(network,64,5,activation='relu') network = tflearn.local_response_normalization(network,4,alpha=0.001/9.0) network = tflearn.max_pool_2d(network,3,2) network = tflearn.fully_connected(network,384,activation='relu',weight_decay=0.004) network = tflearn.fully_connected(network,192,activation='relu',weight_decay=0.004) network = tflearn.fully_connected(network,3,activation='softmax',weight_decay=0.0) return network
def mstarnet(x): network = tflearn.conv_2d(x,18,9,activation='relu') network = tflearn.max_pool_2d(network,6) network = tflearn.conv_2d(network,36,5,activation='relu') network = tflearn.max_pool_2d(network,4) network = tflearn.conv_2d(network,120,4,activation='relu') network = tflearn.fully_connected(network,3,activation='softmax') return network