Пример #1
0
def save_hard_images(
        threshold_list=(0.9999, 0.999, 0.99, 0.97, 0.95, 0.9, 0.8, 0.7, 0.5),
        image_number=1250):

    CustomModel = import_model()
    model = CustomModel()
    factor = 1
    for i, threshold in enumerate(threshold_list):
        print("acquisition::get_hard_images : threshold :", threshold)
        try:

            shutil.rmtree(
                os.path.join(negatives_hard_directory, str(threshold)))
        except FileNotFoundError:
            pass
        os.makedirs(os.path.join(negatives_hard_directory, str(threshold)))

        model.train(image_number, image_number)
        pyramid = Pyramid(model, threshold)
        pyramid.add_false_positive_to_negative_db(directory_path=added_images,
                                                  save_path=os.path.join(
                                                      negatives_hard_directory,
                                                      str(threshold)),
                                                  strides=(9, 9))

        pyramid = Pyramid(model, threshold_list[max(0, i - 1)])
        pyramid.test_pyramide('photo_famille.jpeg')

        factor *= 0.8
        model.recompile(factor)
Пример #2
0
def main(model_num=1):

    preprocess = Preprocess()

    texts_train, labels_train = preprocess.preprocessData(
        '../projet2/train.txt', mode="train")
    texts_dev, labels_dev = preprocess.preprocessData('../projet2/dev.txt',
                                                      mode="train")

    MAX_SEQUENCE_LENGTH = 24
    LSTM_DIM = 64
    HIDDEN_LAYER_DIM = 30
    NUM_CLASSES = 4
    GAUSSIAN_NOISE = 0.1
    DROPOUT = 0.2
    DROPOUT_LSTM = 0.2
    BATCH_SIZE = 200

    X_train, X_val, y_train, y_val = train_test_split(texts_train,
                                                      labels_train,
                                                      test_size=0.2,
                                                      random_state=42)

    labels_categorical_train = to_categorical(np.asarray(y_train))
    labels_categorical_val = to_categorical(np.asarray(y_val))
    labels_categorical_dev = to_categorical(np.asarray(labels_dev))

    embedding = Embedding('../projet2/emosense.300d.txt')
    embeddings = embedding.getMatrix()
    tokenizer = embedding.getTokenizer()

    message_first_message_train, message_second_message_train, message_third_message_train = get_sequences(
        X_train, MAX_SEQUENCE_LENGTH, tokenizer)
    message_first_message_val, message_second_message_val, message_third_message_val = get_sequences(
        X_val, MAX_SEQUENCE_LENGTH, tokenizer)
    message_first_message_dev, message_second_message_dev, message_third_message_dev = get_sequences(
        texts_dev, MAX_SEQUENCE_LENGTH, tokenizer)

    model = CustomModel(model_num)
    model.build(embeddings,
                MAX_SEQUENCE_LENGTH,
                LSTM_DIM,
                HIDDEN_LAYER_DIM,
                NUM_CLASSES,
                noise=GAUSSIAN_NOISE,
                dropout_lstm=DROPOUT_LSTM,
                dropout=DROPOUT)
    model.summary()
    history = model.train(message_first_message_train,
                          message_second_message_train,
                          message_third_message_train,
                          labels_categorical_train, message_first_message_val,
                          message_second_message_val,
                          message_third_message_val, labels_categorical_val)

    y_pred = model.predict([
        message_first_message_dev, message_second_message_dev,
        message_third_message_dev
    ])