示例#1
0
def random_plan(request):
    while True:
        conf = get_random_conf()
        cnn = CNN(conf)
        cnn.train_model(1)
        if 0 in cnn.con_mat_val[-1]:
            continue
        else:
            print 'we find normal model'
            cnn.train_model(10)
示例#2
0
def good_plan(request):
    try:
        # cnn = CNN({'model_name': 'good_plan_50', 'img_rows': 50, 'img_cols': 50})
        cnn = CNN({'model_name': 'good_plan_50'}, True)
        cnn.train_model(40)
    except Exception as e:
        print e
        return Response({'msg': e.message}, status=status.HTTP_400_BAD_REQUEST)
    print 'finish good plan'
    return Response({}, status=status.HTTP_200_OK)
示例#3
0
 def test_train_model(self):
     # cnn = CNN({'model_name': 'split_cases_50_50_2_layer', 'img_rows': 200, 'img_cols': 200})
     # cnn = CNN({'model_name': 'model_with_gabor2'}, True)
     # cnn = CNN({'model_name': 'split_cases_dropout_50', 'img_rows': 200, 'img_cols': 200})
     # cnn = CNN({'model_name': 'test_split_case'}, True)
     # cnn = CNN({'model_name': 'test_split_case', 'img_rows': 200, 'img_cols': 200})
     # cnn = CNN({'model_name': 'third_model', 'img_rows': 200, 'img_cols': 200})
     cnn = CNN({'model_name': 'kernal_5X5'}, True)
     # cnn = CNN({'model_name': 'second_model'}, True)
     # cnn = CNN({'model_name': 'naor_first_model'}, True)
     # cnn._calculate_confusion_matrix()
     # self.assertEqual(cnn.tp, 396)
     # self.assertEqual(cnn.tn, 970)
     # self.assertEqual(cnn.fp, 6)
     # self.assertEqual(cnn.fn, 61)
     cnn.train_model(n_epoch=1)
示例#4
0
 def test_train_model(self):
     _con_mat = [[25, 25, 25, 25], [30, 20, 30, 20], [50, 0, 0, 50]]
     model_name = 'kernal_6X6'
     cnn = CNN({
         'model_name': model_name,
         'img_rows': 75,
         'img_cols': 75,
         'kernel_size': (8, 8)
     })
     cnn.con_mat_train = _con_mat
     cnn.con_mat_val = _con_mat
     cnn._save_only_best()
     self.assertTrue(
         os.path.exists(os.path.join(cnn.model_path + '.h5(weights)')))
     self.assertTrue(os.path.exists(os.path.join(cnn.model_path + '.json')))
     cnn.train_model(1)
     del cnn
     cnn = CNN({'model_name': model_name}, True)
     self.assertEqual(_con_mat, cnn.con_mat_train)
     self.assertEqual(_con_mat, cnn.con_mat_val)
示例#5
0
def full_plan(request):
    try:
        item = 1
        for split_cases in ['True', 'False']:
            for dropout in [0.25, 0.5]:
                for activation_function in ['softmax', 'sigmoid']:
                    for img_size in [(75, 75), (50, 50)]:
                        for nb_filters in [32, 64]:
                            for kernel_size in [5, 6, 7, 8, 9, 10]:
                                for pool_size in [2, 4, 6, 8]:
                                    for batch_size in [32, 64, 128]:
                                        for sigma in [180, 90, 30]:
                                            for theta in [45, 90, 135]:
                                                for lammbd in [45, 90, 135]:
                                                    for gamma in [
                                                            0.3, 0.5, 0.7, 0.9
                                                    ]:
                                                        for psi in [
                                                                0.2, 0.5, 0.8
                                                        ]:
                                                            try:
                                                                item_path = os.path.join(
                                                                    ROOT_DIR,
                                                                    'cnn_models',
                                                                    'item%s.json'
                                                                    % item)
                                                                if os.path.exists(
                                                                        item_path
                                                                ):
                                                                    item += 1
                                                                    break
                                                                params = {}
                                                                params[
                                                                    'model_name'] = "item%s" % item
                                                                item += 1
                                                                params[
                                                                    'split_cases'] = split_cases
                                                                params[
                                                                    'img_rows'] = img_size[
                                                                        0]
                                                                params[
                                                                    'img_cols'] = img_size[
                                                                        1]
                                                                params[
                                                                    'batch_size'] = batch_size
                                                                params[
                                                                    'nb_filters'] = nb_filters
                                                                params[
                                                                    'dropout'] = dropout
                                                                params[
                                                                    'activation_function'] = activation_function
                                                                params[
                                                                    'pool_size'] = pool_size
                                                                params[
                                                                    'kernel_size'] = kernel_size
                                                                params[
                                                                    'sigma'] = sigma
                                                                params[
                                                                    'theta'] = theta
                                                                params[
                                                                    'lammbd'] = lammbd
                                                                params[
                                                                    'gamma'] = gamma
                                                                params[
                                                                    'psi'] = psi

                                                                cnn = CNN(
                                                                    params)
                                                                cnn.train_model(
                                                                    150)
                                                            except Exception as e:
                                                                print e
    except Exception as e:
        print e
        return Response({'msg': e.message}, status=status.HTTP_400_BAD_REQUEST)
    print 'finish all plan'
    return Response({}, status=status.HTTP_200_OK)