(self, resolution=None, sizes=None, modify_sequence=None,
            output_tanh=True)
A pytorch progessive GAN generator that can be converted directly
        from either a tensorflow model or a theano model.  It consists of
        a sequence of convolutional layers, organized in pairs, with an
        upsampling and reduction of channels at every other layer; and
        then finally followed by an output layer that reduces it to an
        RGB [-1..1] image.

        The network can be given more layers to increase the output
        resolution.  The sizes argument indicates the fieature depth at
        each upsampling, starting with the input z: [input-dim, 4x4-depth,
        8x8-depth, 16x16-depth...].  The output dimension is 2 * 2**len(sizes)

        Some default architectures can be selected by supplying the
        resolution argument instead.

        The optional modify_sequence function can be used to transform the
        sequence of layers before the network is constructed.

        If output_tanh is set to False, the network leaves the output
        unclamped; otherwise, it applies a tanh to clamp the output to
        [-1,1] before output.
A pytorch progessive GAN generator that can be converted directly
        from either a tensorflow model or a theano model.  It consists of
        a sequence of convolutional layers, organized in pairs, with an
        upsampling and reduction of channels at every other layer; and
        then finally followed by an output layer that reduces it to an
        RGB [-1..1] image.
A pytorch progessive GAN generator that can be converted directly from either a tensorflow model or a theano model . It consists of a sequence of convolutional layers organized in pairs with an upsampling and reduction of channels at every other layer ; and then finally followed by an output layer that reduces it to an RGB [ - 1 .. 1 ] image .
def __init__(self, resolution=None, sizes=None, modify_sequence=None,
            output_tanh=True):
        '''
        A pytorch progessive GAN generator that can be converted directly
        from either a tensorflow model or a theano model.  It consists of
        a sequence of convolutional layers, organized in pairs, with an
        upsampling and reduction of channels at every other layer; and
        then finally followed by an output layer that reduces it to an
        RGB [-1..1] image.

        The network can be given more layers to increase the output
        resolution.  The sizes argument indicates the fieature depth at
        each upsampling, starting with the input z: [input-dim, 4x4-depth,
        8x8-depth, 16x16-depth...].  The output dimension is 2 * 2**len(sizes)

        Some default architectures can be selected by supplying the
        resolution argument instead.

        The optional modify_sequence function can be used to transform the
        sequence of layers before the network is constructed.

        If output_tanh is set to False, the network leaves the output
        unclamped; otherwise, it applies a tanh to clamp the output to
        [-1,1] before output.
        '''
        assert (resolution is None) != (sizes is None)
        if sizes is None:
            sizes = {
                    8: [512, 512, 512],
                    16: [512, 512, 512, 512],
                    32: [512, 512, 512, 512, 256],
                    64: [512, 512, 512, 512, 256, 128],
                    128: [512, 512, 512, 512, 256, 128, 64],
                    256: [512, 512, 512, 512, 256, 128, 64, 32],
                    1024: [512, 512, 512, 512, 512, 256, 128, 64, 32, 16]
                }[resolution]
        # Follow the schedule of upsampling given by sizes.
        # layers are called: layer1, layer2, etc; then output_128x128
        sequence = []
        def add_d(layer, name=None):
            if name is None:
                name = 'layer%d' % (len(sequence) + 1)
            sequence.append((name, layer))
        add_d(NormConvBlock(sizes[0], sizes[1], kernel_size=4, padding=3))
        add_d(NormConvBlock(sizes[1], sizes[1], kernel_size=3, padding=1))
        for i, (si, so) in enumerate(zip(sizes[1:-1], sizes[2:])):
            add_d(NormUpscaleConvBlock(si, so, kernel_size=3, padding=1))
            add_d(NormConvBlock(so, so, kernel_size=3, padding=1))
        # Create an output layer.  During training, the progressive GAN
        # learns several such output layers for various resolutions; we
        # just include the last (highest resolution) one.
        dim = 4 * (2 ** (len(sequence) // 2 - 1))
        add_d(OutputConvBlock(sizes[-1], tanh=output_tanh),
                name='output_%dx%d' % (dim, dim))
        # Allow the sequence to be modified
        if modify_sequence is not None:
            sequence = modify_sequence(sequence)
        super().__init__(OrderedDict(sequence))
def __init__ ( self , resolution = None , sizes = None , modify_sequence = None , output_tanh = True ) : assert ( resolution is None ) != ( sizes is None ) if sizes is None : sizes = { 8 : [ 512 , 512 , 512 ] , 16 : [ 512 , 512 , 512 , 512 ] , 32 : [ 512 , 512 , 512 , 512 , 256 ] , 64 : [ 512 , 512 , 512 , 512 , 256 , 128 ] , 128 : [ 512 , 512 , 512 , 512 , 256 , 128 , 64 ] , 256 : [ 512 , 512 , 512 , 512 , 256 , 128 , 64 , 32 ] , 1024 : [ 512 , 512 , 512 , 512 , 512 , 256 , 128 , 64 , 32 , 16 ] } [ resolution ] # Follow the schedule of upsampling given by sizes. # layers are called: layer1, layer2, etc; then output_128x128 sequence = [ ] def add_d ( layer , name = None ) : if name is None : name = 'layer%d' % ( len ( sequence ) + 1 ) sequence . append ( ( name , layer ) ) add_d ( NormConvBlock ( sizes [ 0 ] , sizes [ 1 ] , kernel_size = 4 , padding = 3 ) ) add_d ( NormConvBlock ( sizes [ 1 ] , sizes [ 1 ] , kernel_size = 3 , padding = 1 ) ) for i , ( si , so ) in enumerate ( zip ( sizes [ 1 : - 1 ] , sizes [ 2 : ] ) ) : add_d ( NormUpscaleConvBlock ( si , so , kernel_size = 3 , padding = 1 ) ) add_d ( NormConvBlock ( so , so , kernel_size = 3 , padding = 1 ) ) # Create an output layer.  During training, the progressive GAN # learns several such output layers for various resolutions; we # just include the last (highest resolution) one. dim = 4 * ( 2 ** ( len ( sequence ) // 2 - 1 ) ) add_d ( OutputConvBlock ( sizes [ - 1 ] , tanh = output_tanh ) , name = 'output_%dx%d' % ( dim , dim ) ) # Allow the sequence to be modified if modify_sequence is not None : sequence = modify_sequence ( sequence ) super ( ) . __init__ ( OrderedDict ( sequence ) )