Exemple #1
0
def four_class(iter_idx):
    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(4, weight_scale=0.17),
                          SoftmaxLayer()],
                         DataProvider(num_genres=4))

    neural_net.setup_layers((128, 599), (4, ))

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

    f = open('four_class_run' + str(iter_idx) + '.txt', 'w')
    f.write(str(neural_net.results))
    f.close()

    print 'Iteration ' + str(iter_idx)
    print neural_net.results
                          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(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' +\