(params)
return result
Conversion from the old pytorch model layer names.
Conversion from the old pytorch model layer names.
Conversion from the old pytorch model layer names .
def state_dict_from_old_pt_dict(params):
    '''
    Conversion from the old pytorch model layer names.
    '''
    result = {}
    sizes = []
    for i in itertools.count():
        old_layername = 'features.%d' % i
        pt_layername = 'layer%d' % (i + 1)
        try:
            weight = params['%s.conv.weight' % (old_layername)]
        except KeyError:
            break
        if i == 0:
            sizes.append(weight.shape[0])
        if i % 2 == 0:
            sizes.append(weight.shape[1])
        result['%s.conv.weight' % (pt_layername)] = weight
        result['%s.wscale.b' % (pt_layername)] = params[
                '%s.wscale.b' % (old_layername)]
    # Copy the output layers.
    i -= 1
    resolution = 4 * (2 ** (i // 2))
    pt_layername = 'output_%dx%d' % (resolution, resolution)
    result['%s.conv.weight' % pt_layername] = params['output.conv.weight']
    result['%s.wscale.b' % pt_layername] = params['output.wscale.b']
    # Return parameters and also network architecture sizes.
    return result
def state_dict_from_old_pt_dict ( params ) : result = { } sizes = [ ] for i in itertools . count ( ) : old_layername = 'features.%d' % i pt_layername = 'layer%d' % ( i + 1 ) try : weight = params [ '%s.conv.weight' % ( old_layername ) ] except KeyError : break if i == 0 : sizes . append ( weight . shape [ 0 ] ) if i % 2 == 0 : sizes . append ( weight . shape [ 1 ] ) result [ '%s.conv.weight' % ( pt_layername ) ] = weight result [ '%s.wscale.b' % ( pt_layername ) ] = params [ '%s.wscale.b' % ( old_layername ) ] # Copy the output layers. i -= 1 resolution = 4 * ( 2 ** ( i // 2 ) ) pt_layername = 'output_%dx%d' % ( resolution , resolution ) result [ '%s.conv.weight' % pt_layername ] = params [ 'output.conv.weight' ] result [ '%s.wscale.b' % pt_layername ] = params [ 'output.wscale.b' ] # Return parameters and also network architecture sizes. return result