def main_coco():
    #val_path = "data/Definitive/Hexagon/val"
    #val_path = "data/Definitive/Cube/val"
    #val_path = "data/Definitive/Octahedron/val"
    #val_path = "data/Definitive/Needle/val"
    val_path = "data/Random/Cube/val"
    #weights = "logs/Final/Hexagon/orientations_2900.h5"
    #weights = "logs/Final/Cube/orientations_2900.h5"
    #weights = "logs/Final/Needle/orientations_3000.h5"
    weights = "logs/Random/Cube/orientations_1200.h5"
    #weights = "logs/Final/Octahedron/orientations_2900.h5"
    evaluation_dir = "evaluation"
    config = Config()

    dataset_val = FiguresDataset()
    dataset_val.load_figures(val_path, "val_annotations.json")
    dataset_val.prepare()

    val_images, val_orientations, _ = load_figures_data(dataset_val, config, mask=False)

    # Loading model and weights
    or_model = model.OrientationModel("logs", config)

    or_model.compile(weights)

    # Inference
    predictions = detect.detect(or_model, val_images)

    gt_orientations = R.from_euler('ZYX', val_orientations, degrees=True).as_matrix()
    utils.evaluate(gt_orientations, predictions, dataset_val, evaluation_dir)

    coco_data.save_pred_annotations(predictions, dataset_val, val_path, evaluation_dir)

    visualize.show_results(val_images, predictions, evaluation_dir)
Esempio n. 2
0
    def on_data(self, raw_data):
        '''
            :param raw_data: JSON format text corresponding to a tweet object
            :return: (bool) True. Prints tweet id and tweet text if the tweet is found offensive,
            "not offensive" if not.
        '''

        #the following condition may only occur if stop_stream has been executed
        if s.stream_tab.switch_stream["text"] == "":
            s.stream_tab.switch_stream.configure(text="Start stream")
            streamer.disconnect()

        try:
            data = json.loads(raw_data)
            print(data["text"])
            insulting, words = detect(data["text"])
            if insulting:  # A word in the tweet was found in dict
                s.stream_tab.tweets.config(state='normal')
                output = "Offensive words: \"{}\" found in: \n[{}] {}".format(', '.join(words),
                                        data["user"]["screen_name"], strip_smileys(data["text"])) + "\n" \
                                            + "https://twitter.com/{}/status/{}".format(data["user"]["screen_name"], data["id"])  \
                                            + "\n_____________________________________________________\n"
                s.stream_tab.tweets.insert(index='end', chars=output)
                s.stream_tab.tweets.config(state='disabled')
            return True

        except KeyError as error:
            print("oops! Key error encoutered in on_data: {}".format(error))
            return True

        finally:
            #Controlling the rate of streaming.
            sleep(1)
        return False
def main_or():
    IMAGES_DIR = "data/Cube_2.0/Images"
    FILE_PATH = "data/Cube_2.0/cube_quat_angles.csv"
    config = Config()
    weights = "logs/orientations_2300.h5"

    train_images, train_angles, val_images, val_angles = \
        orientation_data.load_dataset(FILE_PATH, IMAGES_DIR, (128, 128), train_per=0.5)

    # Loading model and weights
    or_model = model.OrientationModel("logs", config)
    if weights is not None:
        or_model.compile(weights)

    # Inference
    predictions = detect.detect(or_model, val_images)
    visualize.show_results(val_images, predictions)
def main_coco():
    #dataset_path = "data/Detections/Cube_0.9"
    dataset_path = "data/Detections/Final/Cube"
    #dataset_path = "data/Detections/Final/Octahedron"
    #dataset_path = "data/Detections/Final/Needle"
    #dataset_path = "data/Detections/Final/Hexagon_lat"

    #weights = "logs/Final/Cube/orientations_2900.h5"
    #weights = "logs/Final/Cube/orientations_2900.h5"
    #weights = "logs/Final/Needle/orientations_3000.h5"
    #weights = "logs/Final/Octahedron/orientations_2900.h5"
    weights = "logs/Random/Cube/orientations_1200.h5"
    annotations = "prediction_annotations_90.json"
    pred_dir = "predictions/Final"

    config = Config()

    dataset = FiguresDataset()
    dataset.load_figures(dataset_path, annotations)
    dataset.prepare()

    images, orientations, masks = load_figures_data(dataset, config, mask=True)
    #images = utils.apply_mask(images, masks, extra=3)

    # Loading model and weights
    or_model = model.OrientationModel("logs", config)

    or_model.compile(weights)

    # Inference
    start = time.time()
    predictions = detect.detect(or_model, images)
    end = time.time()
    print(end - start)

    coco_data.save_pred_annotations(predictions, dataset, dataset_path, pred_dir)

    visualize.show_results(images, predictions, pred_dir)
Esempio n. 5
0
 def detect_test(self):
     text = "F**k you, c**t!"
     assert detect(text)[0] == True
     text = "No way he gets back from this."
     assert detect(text)[0] == False