def test_layer_structure_undefined_file_name(self): connection = layers.Input(10) > layers.Sigmoid(1) with reproducible_mktemp(): plots.layer_structure(connection, filepath=None, show=False) temp_filename = tempfile.mktemp() filesize_after = os.path.getsize(temp_filename) self.assertGreater(filesize_after, 0)
def test_that_layer_structure_does_not_fail(self): connection = layers.Input(10) > layers.Sigmoid(1) with tempfile.NamedTemporaryFile() as temp: filesize_before = os.path.getsize(temp.name) plots.layer_structure(connection, filepath=temp.name, show=False) filesize_after = os.path.getsize(temp.name) self.assertEqual(filesize_before, 0) self.assertGreater(filesize_after, filesize_before)
def test_that_layer_structure_for_network(self): connection = layers.Input(10) > layers.Sigmoid(1) network = algorithms.GradientDescent(connection) with tempfile.NamedTemporaryFile() as temp: filesize_before = os.path.getsize(temp.name) plots.layer_structure(network, filepath=temp.name, show=False) filesize_after = os.path.getsize(temp.name) self.assertEqual(filesize_before, 0) self.assertGreater(filesize_after, filesize_before)
def test_layer_structure_ignore_layers_attr(self): input_layer = layers.Input(10) connection = input_layer > layers.Sigmoid(1) with tempfile.NamedTemporaryFile() as temp: plots.layer_structure(connection, filepath=temp.name, show=False, ignore_layers=[]) filesize_first = os.path.getsize(temp.name) with tempfile.NamedTemporaryFile() as temp: plots.layer_structure(connection, filepath=temp.name, show=False, ignore_layers=[layers.Sigmoid]) filesize_second = os.path.getsize(temp.name) # First one should have more layers to draw # than the second one self.assertGreater(filesize_first, filesize_second)
]], layers.Concatenate(), ) googlenet = layers.join( layers.Input((3, None, None)), layers.Convolution((64, 7, 7), padding='half', stride=2), layers.Relu(), layers.MaxPooling((3, 3), stride=2), layers.LocalResponseNorm(alpha=0.00002, k=1), layers.Convolution((64, 1, 1)) > layers.Relu(), layers.Convolution((192, 3, 3), padding='half') > layers.Relu(), layers.LocalResponseNorm(alpha=0.00002, k=1), layers.MaxPooling((3, 3), stride=2), Inception((32, 64, 96, 128, 16, 32)), Inception((64, 128, 128, 192, 32, 96)), layers.MaxPooling((3, 3), stride=2), Inception((64, 192, 96, 208, 16, 48)), Inception((64, 160, 112, 224, 24, 64)), Inception((64, 128, 128, 256, 24, 64)), Inception((64, 112, 144, 288, 32, 64)), Inception((128, 256, 160, 320, 32, 128)), layers.MaxPooling((3, 3), stride=2), Inception((128, 256, 160, 320, 32, 128)), Inception((128, 384, 192, 384, 48, 128)), layers.GlobalPooling(function=T.mean), layers.Softmax(1000), ) plots.layer_structure(googlenet)
) resnet50 = layers.join( layers.Input((3, 224, 224)), layers.Convolution((64, 7, 7), stride=2, padding=3), layers.BatchNorm(), layers.Relu(), layers.MaxPooling((3, 3), stride=(2, 2), ignore_border=False), ResidualUnit(64, 256, stride=1, has_branch=True), ResidualUnit(64, 256, stride=1), ResidualUnit(64, 256, stride=1), ResidualUnit(128, 512, stride=2, has_branch=True), ResidualUnit(128, 512, stride=1), ResidualUnit(128, 512, stride=1), ResidualUnit(128, 512, stride=1), ResidualUnit(256, 1024, stride=2, has_branch=True), ResidualUnit(256, 1024, stride=1), ResidualUnit(256, 1024, stride=1), ResidualUnit(256, 1024, stride=1), ResidualUnit(256, 1024, stride=1), ResidualUnit(256, 1024, stride=1), ResidualUnit(512, 2048, stride=2, has_branch=True), ResidualUnit(512, 2048, stride=1), ResidualUnit(512, 2048, stride=1), layers.GlobalPooling(), layers.Reshape(), layers.Softmax(1000), ) plots.layer_structure(resnet50)
], [ layers.MaxPooling((3, 3), stride=(2, 2)) ]], layers.Concatenate(), Inception_2([[192], [128, 128, 192], [128, 128, 128, 128, 192], [192]]), Inception_2([[192], [160, 160, 192], [160, 160, 160, 160, 192], [192]]), Inception_2([[192], [160, 160, 192], [160, 160, 160, 160, 192], [192]]), Inception_2([[192], [192, 192, 192], [192, 192, 192, 192, 192], [192]]), [[ ConvReluBN((192, 1, 1)), ConvReluBN((320, 3, 3), stride=2), ], [ ConvReluBN((192, 1, 1)), ConvReluBN((192, 1, 7), padding=(0, 3)), ConvReluBN((192, 7, 1), padding=(3, 0)), ConvReluBN((192, 3, 3), stride=2), ], [ layers.MaxPooling((3, 3), stride=(2, 2)) ]], layers.Concatenate(), Inception_3(pooling='average'), Inception_3(pooling='max'), layers.GlobalPooling(), layers.Softmax(1000), ) plots.layer_structure(inception_v3)
layers.Input((3, None, None)), layers.Convolution((64, 7, 7), padding='half', stride=2), layers.Relu(), layers.MaxPooling((3, 3), stride=2), layers.LocalResponseNorm(alpha=0.00002, k=1), layers.Convolution((64, 1, 1)) > layers.Relu(), layers.Convolution((192, 3, 3), padding='half') > layers.Relu(), layers.LocalResponseNorm(alpha=0.00002, k=1), layers.MaxPooling((3, 3), stride=2), Inception((32, 64, 96, 128, 16, 32)), Inception((64, 128, 128, 192, 32, 96)), layers.MaxPooling((3, 3), stride=2), Inception((64, 192, 96, 208, 16, 48)), Inception((64, 160, 112, 224, 24, 64)), Inception((64, 128, 128, 256, 24, 64)), Inception((64, 112, 144, 288, 32, 64)), Inception((128, 256, 160, 320, 32, 128)), layers.MaxPooling((3, 3), stride=2), Inception((128, 256, 160, 320, 32, 128)), Inception((128, 384, 192, 384, 48, 128)), layers.GlobalPooling(function=T.mean), layers.Softmax(1000), ) plots.layer_structure(googlenet)
layers.BatchNorm(), layers.Relu(), layers.MaxPooling((3, 3), stride=(2, 2), ignore_border=False), ResidualUnit(64, 256, stride=1, has_branch=True), ResidualUnit(64, 256, stride=1), ResidualUnit(64, 256, stride=1), ResidualUnit(128, 512, stride=2, has_branch=True), ResidualUnit(128, 512, stride=1), ResidualUnit(128, 512, stride=1), ResidualUnit(128, 512, stride=1), ResidualUnit(256, 1024, stride=2, has_branch=True), ResidualUnit(256, 1024, stride=1), ResidualUnit(256, 1024, stride=1), ResidualUnit(256, 1024, stride=1), ResidualUnit(256, 1024, stride=1), ResidualUnit(256, 1024, stride=1), ResidualUnit(512, 2048, stride=2, has_branch=True), ResidualUnit(512, 2048, stride=1), ResidualUnit(512, 2048, stride=1), layers.GlobalPooling(), layers.Reshape(), layers.Softmax(1000), ) plots.layer_structure(resnet50)