예제 #1
0
    l1_conv_filter_type=[
        [layer1, l1_conv_filter_type[0], -1, 'valid', (k[0], 1), 0.5],
        [layer1, l1_conv_filter_type[1], -1, 'valid', (k[0], 1), 0.],
        [layer1, l1_conv_filter_type[2], -1, 'valid', (k[0], 1), 0.],
    ],
    l2_conv_filter_type=[
        [layer2, l2_conv_filter_type[0], -1, 'valid', (k[1], 1), 0.5]
    ],
    full_connected_layer_units=[hidden1, hidden2],
    output_dropout_rate=0.2,
    nb_epoch=nb_epoch,
    earlyStoping_patience=50,
    optimizers='sgd',
    batch_size=32,
    lr=1e-2,
)
bow_cnn.print_model_descibe()

print(bow_cnn.fit(
    (train_X_feature, train_y),
    (test_X_feature, test_y)))

y_pred, is_correct, accu, f1, test_loss = bow_cnn.accuracy((test_X_feature, test_y))
result_file_path = 'result/single_bow3_%s_%d.csv' % (feature_type, rand_seed)
data_util.save_result(test_data, predict=y_pred, is_correct=is_correct, path=result_file_path)

end_time = timeit.default_timer()
print('end! Running time:%ds!' % (end_time - start_time))
logging.debug('=' * 20)
logging.debug('end! Running time:%ds!' % (end_time - start_time))
예제 #2
0
                            [layer1, l1_conv_filter_type[2], -1, 'valid', (k[0], 1), 0.],
                        ],
                        l2_conv_filter_type=[
                            [layer2, l2_conv_filter_type[0], -1, 'valid', (k[1], 1), 0.5]
                        ],
                        full_connected_layer_units=[hidden1, hidden2],
                        output_dropout_rate=0.2,
                        nb_epoch=nb_epoch,
                        earlyStoping_patience=50,
                        optimizers='sgd',
                        batch_size=32,
                        lr=1e-2,
                    )

                    dev_loss, dev_accuracy, \
                    val_loss, val_accuracy = bow_cnn.fit((dev_X,  dev_y),(val_X, val_y))
                    print('dev:%f,%f'%(dev_loss, dev_accuracy))
                    print('val:%f,%f'%(val_loss, val_accuracy))
                    fout.write('dev:%f,%f\n'%(dev_loss, dev_accuracy))
                    fout.write('val:%f,%f\n'%(val_loss, val_accuracy))
                    # y_pred, is_correct, accu, f1, test_loss = bow_cnn.accuracy((val_X, val_y))
                    ave_acc.append(val_accuracy)
                print(ave_acc)
                print(np.average(ave_acc))
                print('-' * 80)

                fout.write('五折验证结果:%s\n'%ave_acc)
                fout.write('平均:%f\n'%np.average(ave_acc))
                fout.write('-' * 80 + '\n')

                bow_cnn = SingleChannelBowCNN(