Пример #1
0
def eight_class():
    neural_net = ConvNet([ConvLayer(32, (128, 4), weight_scale=0.044, padding_mode=False),
                          ActivationLayer('leakyReLU'),
                          MaxPoolingLayerCUDA((1, 4)),

                          ConvLayer(32, (32, 4), weight_scale=0.088, padding_mode=False),
                          ActivationLayer('leakyReLU'),
                          MaxPoolingLayerCUDA((1, 2)),

                          ConvLayer(32, (32, 4), weight_scale=0.088, padding_mode=False),
                          ActivationLayer('leakyReLU'),
                          GlobalPoolingLayer(),

                          FullyConnectedLayer(32, weight_scale=0.125),
                          ActivationLayer('leakyReLU'),
                          FullyConnectedLayer(32, weight_scale=0.125),
                          ActivationLayer('leakyReLU'),
                          FullyConnectedLayer(8, weight_scale=0.17),
                          SoftmaxLayer()],
                         DataProvider(num_genres=8))

    neural_net.init_params_from_file(conv_only=True)

    time1 = time.time()
    neural_net.train(learning_rate=0.005, num_iters=80, lrate_schedule=True)
    time2 = time.time()
    print('Time taken: %.1fs' % (time2 - time1))

    print "\nRESULTS:\n"
    for result in neural_net.results:
        print result
        for val in neural_net.results[result]:
            print val

    neural_net.serialise_params()
                          MaxPoolingLayerCUDA((1, 2)),

                          ConvLayer(32, (32, 4), weight_scale=0.088, padding_mode=False),
                          ActivationLayer('leakyReLU'),
                          GlobalPoolingLayer(),

                          FullyConnectedLayer(32, weight_scale=0.125),
                          ActivationLayer('leakyReLU'),
                          FullyConnectedLayer(32, weight_scale=0.125),
                          ActivationLayer('leakyReLU'),
                          FullyConnectedLayer(6, weight_scale=0.17),
                          SoftmaxLayer()],
                         DataProvider(num_genres=6))

    neural_net.setup_layers((128, 599), (6, ))
    neural_net.init_params_from_file()

    genres = ['classical', 'metal', 'blues', 'disco', 'hiphop', 'reggae']

    for genre in genres:
        for layer_id in range(3):
            activations_for_test_data = neural_net.test_data_activations_for_conv_layer(
                layer_id + 1, genre)

            for result in activations_for_test_data:
                for filter_idx in range(result['filter_activations'].shape[0]):
                    x = np.arange(0, result['filter_activations'].shape[1], 1)
                    y = result['filter_activations'][filter_idx]

                    dir_path = './activations/6genres/conv_layer' + str(layer_id + 1) + '/filter' +\
                               str(filter_idx + 1)