def update_json(inp_data, mode):
    updated_data = []
    ctr = 0
    for example in inp_data:
        bmpmaker.clear()
        if mode == "relative":
            true_seq_relative = RelativeEventSequence.from_eval_str(example["y_ref"])
            true_events_absolute = AbsoluteEventSequence.from_relative(true_seq_relative, width, width).events
            pred_seq_relative = RelativeEventSequence.from_eval_str(example["y_pred"])
            pred_events_absolute = AbsoluteEventSequence.from_relative(pred_seq_relative, width, width).events
        elif mode == "cursor":
            true_seq_cursor = CursorEventSequence.from_eval_str(example["y_ref"])
            true_events_absolute = AbsoluteEventSequence.from_cursor(true_seq_cursor, width, width).events
            pred_seq_cursor = CursorEventSequence.from_eval_str(example["y_pred"])
            pred_events_absolute = AbsoluteEventSequence.from_cursor(pred_seq_cursor, width, width).events
        else:
            raise Exception("Unknown or unsupported mode: {}".format(mode))

        bmpmaker.process_commands(true_events_absolute)
        true_bitmap = np.array(bmpmaker.bitmap)

        bmpmaker.clear()
        bmpmaker.process_commands(pred_events_absolute)
        pred_bitmap = np.array(bmpmaker.bitmap)
        hamming = evaluate(true_bitmap, pred_bitmap)
        example["hamming_distance"] = hamming
        updated_data.append(example)
        ctr += 1

        if ctr % 500 == 0:
            print "Progress: %d" % ctr

    return updated_data
def convert_commands_to_bitmap(bmpmaker, commands_str, mode):
    bmpmaker.clear()
    if mode == "relative":
        rel_seq = RelativeEventSequence.from_eval_str(commands_str)
        abs_seq = AbsoluteEventSequence.from_relative(rel_seq, bmpmaker.shape()[0], bmpmaker.shape()[1])
    elif mode == "cursor":
        cur_seq = CursorEventSequence.from_eval_str(commands_str)
        abs_seq = AbsoluteEventSequence.from_cursor(cur_seq, bmpmaker.shape()[0], bmpmaker.shape()[1])
        
    bmpmaker.process_commands(abs_seq.events)
    return (bmpmaker.bitmap.copy(), bmpmaker.ordered_actions)
Exemple #3
0
def update_json(inp_data, mode):
    updated_data = []
    ctr = 0
    for example in inp_data:
        bmpmaker.clear()
        if mode == "relative":
            true_seq_relative = RelativeEventSequence.from_eval_str(
                example["y_ref"])
            true_events_absolute = AbsoluteEventSequence.from_relative(
                true_seq_relative, width, width).events
            pred_seq_relative = RelativeEventSequence.from_eval_str(
                example["y_pred"])
            pred_events_absolute = AbsoluteEventSequence.from_relative(
                pred_seq_relative, width, width).events
        elif mode == "cursor":
            true_seq_cursor = CursorEventSequence.from_eval_str(
                example["y_ref"])
            true_events_absolute = AbsoluteEventSequence.from_cursor(
                true_seq_cursor, width, width).events
            pred_seq_cursor = CursorEventSequence.from_eval_str(
                example["y_pred"])
            pred_events_absolute = AbsoluteEventSequence.from_cursor(
                pred_seq_cursor, width, width).events
        else:
            raise Exception("Unknown or unsupported mode: {}".format(mode))

        bmpmaker.process_commands(true_events_absolute)
        true_bitmap = np.array(bmpmaker.bitmap)

        bmpmaker.clear()
        bmpmaker.process_commands(pred_events_absolute)
        pred_bitmap = np.array(bmpmaker.bitmap)
        hamming = evaluate(true_bitmap, pred_bitmap)
        example["hamming_distance"] = hamming
        updated_data.append(example)
        ctr += 1

        if ctr % 500 == 0:
            print "Progress: %d" % ctr

    return updated_data
def convert_commands_to_image_sequence(bmpmaker, imgmaker, commands_str, fprefix, mode):
    bmpmaker.clear()
    if mode == "relative":
        rel_seq = RelativeEventSequence.from_eval_str(commands_str)
        abs_seq = AbsoluteEventSequence.from_relative(rel_seq, bmpmaker.shape()[0], bmpmaker.shape()[1])
    elif mode == "cursor":
        cur_seq = CursorEventSequence.from_eval_str(commands_str)
        abs_seq = AbsoluteEventSequence.from_cursor(cur_seq, bmpmaker.shape()[0], bmpmaker.shape()[1])
        
    imgmaker.save_bitmap(bmpmaker.bitmap, "{}{:04d}.gif".format(fprefix,0))
    for i,c in enumerate(abs_seq.events):
        bmpmaker.process_command(c)
        imgmaker.save_bitmap(bmpmaker.bitmap, "{}{:04d}.gif".format(fprefix,i+1))
def convert_commands_to_image_sequence(bmpmaker, imgmaker, commands_str,
                                       fprefix, mode):
    bmpmaker.clear()
    if mode == "relative":
        rel_seq = RelativeEventSequence.from_eval_str(commands_str)
        abs_seq = AbsoluteEventSequence.from_relative(rel_seq,
                                                      bmpmaker.shape()[0],
                                                      bmpmaker.shape()[1])
    elif mode == "cursor":
        cur_seq = CursorEventSequence.from_eval_str(commands_str)
        abs_seq = AbsoluteEventSequence.from_cursor(cur_seq,
                                                    bmpmaker.shape()[0],
                                                    bmpmaker.shape()[1])

    imgmaker.save_bitmap(bmpmaker.bitmap, "{}{:04d}.gif".format(fprefix, 0))
    for i, c in enumerate(abs_seq.events):
        bmpmaker.process_command(c)
        imgmaker.save_bitmap(bmpmaker.bitmap,
                             "{}{:04d}.gif".format(fprefix, i + 1))