try:
    from tensorflow.keras.optimizers import Adam, SGD, RMSprop
except:
    from tensorflow.python.keras.optimizers import Adam, SGD, RMSprop

def hyperparameters_processing(hyperparameters):

    if hyperparameters['optimizer'] == "RMSprop":
        hyperparameters['optimizer'] = RMSprop
    elif hyperparameters['optimizer'] == "SGD":
        hyperparameters['optimizer'] = SGD
    else:
        hyperparameters['optimizer'] = Adam

    return hyperparameters

def get_hyperparameters(task):
    task_dict = {
        '1a': {'lr': .0001, 'batch_size': 8, 'epochs': 50, 'batch_norm': False, 'dropout': [],
                   'spatial_dropout': [], 'optimizer': 'Adam', 'loss': 'binary_crossentropy',
                'metrics': ['binary_accuracy'],
                'model': 'alexnet', 'dense_units': [64, 64, 1], 'dense_activation': ['relu', 'relu', 'sigmoid'],
               'base': 8, 'input_shape': (128, 128, 1), 'data_path': '/Lab1/Skin/', 'pattern': ['Mel', 'Nev'],
               'use_gen': False, 'use_pretrained': False, 'show_visualization': False},
        '1b': {'lr': .0001, 'batch_size': 8, 'epochs': 50, 'batch_norm': True, 'dropout': [],
                   'spatial_dropout': [], 'optimizer': 'Adam', 'loss': 'binary_crossentropy',
                'metrics': ['binary_accuracy'],
                'model': 'alexnet', 'dense_units': [64, 64, 1], 'dense_activation': ['relu', 'relu', 'sigmoid'],
               'base': 8, 'input_shape': (128, 128, 1), 'data_path': '/Lab1/Skin/', 'pattern': ['Mel', 'Nev'],
               'use_gen': False, 'use_pretrained': False, 'show_visualization': False},
        '1c1': {'lr': .00001, 'batch_size': 8, 'epochs': 80, 'batch_norm': False, 'dropout': [],
               'spatial_dropout': [], 'optimizer': 'Adam', 'loss': 'binary_crossentropy',
                'metrics': ['binary_accuracy'],
                'model': 'alexnet', 'dense_units': [64, 64, 1], 'dense_activation': ['relu', 'relu', 'sigmoid'],
               'base': 8, 'input_shape': (128, 128, 1), 'data_path': '/Lab1/Skin/', 'pattern': ['Mel', 'Nev'],
                'use_gen': False, 'use_pretrained': False}, 'show_visualization': False,
        '1c2': {'lr': .00001, 'batch_size': 8, 'epochs': 80, 'batch_norm': True, 'dropout': [],
                'spatial_dropout': [], 'optimizer': 'Adam', 'loss': 'binary_crossentropy',
                'metrics': ['binary_accuracy'],
                'model': 'alexnet', 'dense_units': [64, 64, 1], 'dense_activation': ['relu', 'relu', 'sigmoid'],
                'base': 8, 'input_shape': (128, 128, 1), 'data_path': '/Lab1/Skin/', 'pattern': ['Mel', 'Nev'],
                'use_gen': False, 'use_pretrained': False, 'show_visualization': False},
        '2a': {'lr': .00001, 'batch_size': 8, 'epochs': 80, 'batch_norm': True, 'dropout': [.4, .4],
                'spatial_dropout': [], 'optimizer': 'Adam', 'loss': 'binary_crossentropy',
                'metrics': ['binary_accuracy'],
                'model': 'alexnet', 'dense_units': [64, 64, 1], 'dense_activation': ['relu', 'relu', 'sigmoid'],
                'base': 8, 'input_shape': (128, 128, 1), 'data_path': '/Lab1/Skin/', 'pattern': ['Mel', 'Nev'],
                'use_gen': False, 'use_pretrained': False},
        '2b': {'lr': .00001, 'batch_size': 8, 'epochs': 80, 'batch_norm': False, 'dropout': [.4, .4],
              'spatial_dropout': [], 'optimizer': 'Adam', 'loss': 'binary_crossentropy',
                'metrics': ['binary_accuracy'],
                'model': 'alexnet', 'dense_units': [64, 64, 1], 'dense_activation': ['relu', 'relu', 'sigmoid'],
                'base': 8, 'input_shape': (128, 128, 1), 'data_path': '/Lab1/Skin/', 'pattern': ['Mel', 'Nev'],
               'use_gen': False, 'use_pretrained': False, 'show_visualization': False},
        '3a': {'lr': .00001, 'batch_size': 8, 'epochs': 150, 'batch_norm': False, 'dropout': [.4, .4],
                'spatial_dropout': [.1, .1, .1], 'optimizer': 'Adam', 'loss': 'binary_crossentropy',
                'metrics': ['binary_accuracy'],
                'model': 'alexnet', 'dense_units': [64, 64, 1], 'dense_activation': ['relu', 'relu', 'sigmoid'],
                'base': 64, 'input_shape': (128, 128, 1), 'data_path': '/Lab1/Skin/', 'pattern': ['Mel', 'Nev'],
                'use_gen': False, 'use_pretrained': False, 'show_visualization': False},
        '3b': {'lr': .00001, 'batch_size': 8, 'epochs': 150, 'batch_norm': False, 'dropout': [],
               'spatial_dropout': [], 'optimizer': 'Adam', 'loss': 'binary_crossentropy',
                'metrics': ['binary_accuracy'],
                'model': 'alexnet', 'dense_units': [64, 64, 1], 'dense_activation': ['relu', 'relu', 'sigmoid'],
               'base': 64, 'input_shape': (128, 128, 1), 'data_path': '/Lab1/Skin/', 'pattern': ['Mel', 'Nev'],
               'use_gen': False, 'use_pretrained': False, 'show_visualization': False},
        '4a': {'lr': .00001, 'batch_size': 8, 'epochs': 150, 'batch_norm': True, 'dropout': [.4, .4],
               'spatial_dropout': [.1, .1, .1, .1, .1], 'optimizer': 'Adam', 'loss': 'binary_crossentropy',
                'metrics': ['binary_accuracy'],
                'model': 'vgg16', 'dense_units': [64, 64, 1], 'dense_activation': ['relu', 'relu', 'sigmoid'],
               'base': 16, 'input_shape': (128, 128, 1), 'data_path': '/Lab1/Skin/', 'pattern': ['Mel', 'Nev'],
               'use_gen': False, 'use_pretrained': False, 'show_visualization': False},
        '4b': {'lr': .00001, 'batch_size': 8, 'epochs': 150, 'batch_norm': True, 'dropout': [.4, .4],
               'spatial_dropout': [.1, .1, .1, .1, .1], 'optimizer': 'Adam', 'loss': 'binary_crossentropy',
               'metrics': ['binary_accuracy'],
               'model': 'vgg16', 'dense_units': [64, 64, 1], 'dense_activation': ['relu', 'relu', 'sigmoid'],
               'base': 8, 'input_shape': (128, 128, 1), 'data_path': '/Lab1/Bone/', 'pattern': ['AFF', 'NFF'],
               'use_gen': False, 'use_pretrained': False, 'show_visualization': False},
        '6': {'lr': .00001, 'batch_size': 8, 'epochs': 80, 'batch_norm': True, 'dropout': [.4, .4],
              'spatial_dropout': [], 'optimizer': 'Adam', 'loss': 'binary_crossentropy',
                'metrics': ['binary_accuracy'],
                'model': 'alexnet', 'dense_units': [128, 64, 1], 'dense_activation': ['relu', 'relu', 'sigmoid'],
              'base': 64, 'input_shape': (128, 128, 3), 'data_path': '/Lab1/Lab2/Skin/', 'pattern': ['Mel', 'Nev'],
              'use_gen': True, 'use_pretrained': False, 'show_visualization': False,
              'gen': {'rescale': 1. / 255, 'rotation_range': 10, 'width_shift_range': .1,
                      'height_shift_range': .1, 'horizontal_flip': True, 'zoom_range': 0},
              'gen_test': {'rescale': 1. / 255, 'rotation_range': 0, 'width_shift_range': 0,
                           'height_shift_range': 0, 'horizontal_flip': False, 'zoom_range': 0}},
        '7a': {'lr': .00001, 'batch_size': 8, 'epochs': 80, 'batch_norm': True, 'dropout': [.4, .4],
              'spatial_dropout': [], 'optimizer': 'Adam', 'loss': 'binary_crossentropy',
                'metrics': ['binary_accuracy'],
                'model': 'vgg16', 'dense_units': [64, 64, 1], 'dense_activation': ['relu', 'relu', 'sigmoid'],
              'base': 64, 'input_shape': (128, 128, 3), 'data_path': '/Lab1/Lab2/Skin/', 'pattern': ['Mel', 'Nev'],
              'use_gen': True, 'use_pretrained': False, 'show_visualization': False,
              'gen': {'rescale': 1. / 255, 'rotation_range': 10, 'width_shift_range': .1,
                      'height_shift_range': .1, 'horizontal_flip': True, 'zoom_range': 0},
              'gen_test': {'rescale': 1. / 255, 'rotation_range': 0, 'width_shift_range': 0,
                           'height_shift_range': 0, 'horizontal_flip': False, 'zoom_range': 0}},
        '7b': {'lr': .00001, 'batch_size': 8, 'epochs': 80, 'batch_norm': True, 'dropout': [.4, .4],
              'spatial_dropout': [], 'optimizer': 'Adam', 'loss': 'binary_crossentropy',
                'metrics': ['binary_accuracy'],
                'model': 'vgg16', 'dense_units': [64, 64, 1], 'dense_activation': ['relu', 'relu', 'sigmoid'],
              'base': 64, 'input_shape': (128, 128, 1), 'data_path': '/Lab1/Lab2/Bone/', 'pattern': ['AFF', 'NFF'],
              'use_gen': True, 'use_pretrained': False, 'show_visualization': False,
              'gen': {'rescale': 1. / 255, 'rotation_range': 10, 'width_shift_range': .1,
                      'height_shift_range': .1, 'horizontal_flip': True, 'zoom_range': 0},
              'gen_test': {'rescale': 1. / 255, 'rotation_range': 0, 'width_shift_range': 0,
                           'height_shift_range': 0, 'horizontal_flip': False, 'zoom_range': 0}},

        '9a': {'lr': .00001, 'batch_size': 8, 'epochs': 150, 'batch_norm': False, 'dropout': [.4, .4],
              'spatial_dropout': [], 'optimizer': 'Adam', 'loss': 'binary_crossentropy',
              'metrics': ['binary_accuracy'],
              'model': 'alexnet', 'dense_units': [128, 64, 1], 'dense_activation': ['relu', 'relu', 'sigmoid'],
              'base': 64, 'input_shape': (224, 224, 3), 'data_path': '/Lab1/Lab2/Skin/', 'pattern': ['Mel', 'Nev'],
              'use_gen': True,
              'gen': {'rescale': 1. / 255, 'rotation_range': 10, 'width_shift_range': .1,
                      'height_shift_range': .1, 'horizontal_flip': True, 'zoom_range': 0},
              'gen_test': {'rescale': 1. / 255, 'rotation_range': 0, 'width_shift_range': 0,
                           'height_shift_range': 0, 'horizontal_flip': False, 'zoom_range': 0},
              'use_pretrained': True,
              'pretrained_prop': {
                  'pretrained_model': "vgg16", "include_top": False, "weights": "imagenet",
                  'added_layers': ["Flatten","Dense", "Activation", "Dropout", "Dense","Activation"],
                  'added_layers_parameters': ["-1","128", "relu", ".5" , "1","sigmoid"],
                  'base_model_trainable': False}, 'show_visualization': False
              },
        '9b': {'lr': .00001, 'batch_size': 8, 'epochs': 150, 'batch_norm': False, 'dropout': [.4, .4],
              'spatial_dropout': [], 'optimizer': 'Adam', 'loss': 'binary_crossentropy',
              'metrics': ['binary_accuracy'],
              'model': 'alexnet', 'dense_units': [128, 64, 1], 'dense_activation': ['relu', 'relu', 'sigmoid'],
              'base': 64, 'input_shape': (224, 224, 3), 'data_path': '/Lab1/Lab2/Bone/', 'pattern': ['AFF', 'NFF'],
              'use_gen': True,
              'gen': {'rescale': 1. / 255, 'rotation_range': 10, 'width_shift_range': .1,
                      'height_shift_range': .1, 'horizontal_flip': True, 'zoom_range': 0},
              'gen_test': {'rescale': 1. / 255, 'rotation_range': 0, 'width_shift_range': 0,
                           'height_shift_range': 0, 'horizontal_flip': False, 'zoom_range': 0},
              'use_pretrained': True,
              'pretrained_prop': {
                  'pretrained_model': "vgg16", "include_top": False, "weights": "imagenet",
                  'added_layers': ["Flatten","Dense", "Activation", "Dropout", "Dense","Activation"],
                  'added_layers_parameters': ["-1","128", "relu", ".5" , "1","sigmoid"],
                  'base_model_trainable': False}, 'show_visualization': False
              },
        '10': {'lr': .00001, 'batch_size': 8, 'epochs': 50, 'batch_norm': False, 'dropout': [.4, .4],
               'spatial_dropout': [], 'optimizer': 'Adam', 'loss': 'categorical_crossentropy',
               'metrics': ['accuracy'],
               'model': 'alexnet', 'dense_units': [64, 64, 2], 'dense_activation': ['relu', 'relu', 'softmax'],
               'base': 64, 'input_shape': (224, 224, 3), 'data_path': '/Lab1/Lab2/Bone/', 'pattern': ['AFF', 'NFF'],
               'use_gen': True,
               'gen': {'rescale': 1. / 255, 'rotation_range': 10, 'width_shift_range': .1,
                       'height_shift_range': .1, 'horizontal_flip': True, 'zoom_range': 0},
               'gen_test': {'rescale': 1. / 255, 'rotation_range': 0, 'width_shift_range': 0,
                            'height_shift_range': 0, 'horizontal_flip': False, 'zoom_range': 0},
               'use_pretrained': False, 'show_visualization': True
               },
        'bonus_task': {'lr': .00001, 'batch_size': 8, 'epochs': 50, 'batch_norm': False, 'dropout': [],
               'spatial_dropout': [], 'optimizer': 'Adam', 'loss': 'categorical_crossentropy',
               'metrics': ['accuracy'],
               'model': 'resnet', 'dense_units': [2], 'dense_activation': ['softmax'],
               'base': 64, 'input_shape': (224, 224, 1), 'data_path': '/Lab1/Lab2/Bone/', 'pattern': ['AFF', 'NFF'],
               'use_gen': True,
               'gen': {'rescale': 1. / 255, 'rotation_range': 10, 'width_shift_range': .1,
                       'height_shift_range': .1, 'horizontal_flip': True, 'zoom_range': 0},
               'gen_test': {'rescale': 1. / 255, 'rotation_range': 0, 'width_shift_range': 0,
                            'height_shift_range': 0, 'horizontal_flip': False, 'zoom_range': 0},
               'use_pretrained': False, 'show_visualization': False
               }
    }
    return task_dict[task]
