コード例 #1
0
def check_dc_generator():
    """Checks the output and number of parameters of the DCGenerator class.
    """
    state = torch.load('checker_files/dc_generator.pt')

    G = DCGenerator(noise_size=100, conv_dim=32)
    G.load_state_dict(state['state_dict'])
    noise = state['input']
    dc_generator_expected = state['output']

    output = G(noise)
    output_np = output.data.cpu().numpy()

    if np.allclose(output_np, dc_generator_expected):
        print('DCGenerator output: EQUAL')
    else:
        print('DCGenerator output: NOT EQUAL')

    num_params = count_parameters(G)
    expected_params = 370624

    print('DCGenerator #params = {}, expected #params = {}, {}'.format(
        num_params, expected_params,
        'EQUAL' if num_params == expected_params else 'NOT EQUAL'))

    print('-' * 80)
コード例 #2
0
def check_dc_generator():
    """Checks the output and number of parameters of the DCGenerator class.
    """
    state = torch.load('/home/love_you/Documents/Study/deep_learning/a4-code/a4-code-v2-updated/checker_files/dc_generator.pt')
    # print(state['state_dict'].keys())
    G = DCGenerator(noise_size=100, conv_dim=32)
    # for name, param in G.named_parameters():
    #     print(name)

    # summary(G, input_size=(100, 1, 1))
    G.load_state_dict(state['state_dict'])
    noise = state['input']
    dc_generator_expected = state['output']

    output = G(noise)
    output_np = output.data.cpu().numpy()

    if np.allclose(output_np, dc_generator_expected):
        print('DCGenerator output: EQUAL')
    else:
        print('DCGenerator output: NOT EQUAL')

    num_params = count_parameters(G)
    expected_params = 370624

    print('DCGenerator #params = {}, expected #params = {}, {}'.format(
          num_params, expected_params, 'EQUAL' if num_params == expected_params else 'NOT EQUAL'))

    print('-' * 80)