# Path: lib/replay_memory.py
# class ReplayMemory(object):
#     def __init__(self, filepath, max_size, max_size_tolerance):
#     def create_instance_supervised(val=False):
#     def create_instance_reinforced(val=False):
#     def create_instance_by_config(cfg_name):
#     def add_states(self, states, shrink=True):
#     def add_state(self, state, commit=True, shrink=True):
#     def update_state(self, idx, state, commit=True):
#     def get_state_by_id(self, idx):
#     def get_states_by_ids(self, ids):
#     def get_random_states(self, count):
#     def get_states_range(self, pos_start, length):
#     def get_random_state_chain(self, length, from_pos_range=None):
#     def get_random_state_chain_timediff(self, length, max_timediff_ms=500, depth=50):
#     def update_caches(self):
#     def is_above_tolerance(self):
#     def shrink_to_max_size(self, force=False):
#     def commit(self):
#     def close(self):
#     def connect(self):
# 
# Path: lib/util.py
# def template_match(needle, haystack):
# def compress_to_jpg(img):
# def compress_img(img, method):
# def decompress_img(img_compressed):
# def draw_image(img, other_img, x, y, copy=True, raise_if_oob=False):
# def draw_point(img, y, x, size=5, color=[255, 0, 0], alpha=1.0, copy=True):
# def draw_line(img, y1, x1, y2, x2, color=[0, 255, 0], alpha=1.0, thickness=1, clip_result=True, copy=True):
# def draw_direction_circle(img, y, x, r_inner, r_outer, angle_start, angle_end, color_border=[0, 255, 0], color_fill=[0, 200, 0], alpha=1.0):
# def draw_text(img, y, x, text, color=[0, 255, 0], size=25):
# def to_variable(inputs, volatile=False, requires_grad=True):
# def to_variables(inputs, volatile=False, requires_grad=True):
# def to_cuda(inputs, gpu=Config.GPU):
# def to_numpy(var):
# def draw_heatmap_overlay(img, heatmap, alpha=0.5):
# def create_2d_gaussian_old(size, fwhm=3, center=None):
# def create_2d_gaussian(size, sigma):
# FONT_CACHE = dict()


import sys
import os
import train
import numpy as np
import cPickle as pickle
import gzip as gz
import random
from lib import replay_memory
from lib import util
                    if not key in examples:
                        examples[key] = dataset_state_idx_to_example(state_idx, memory)
                    examples[key].add_grid(grid_key, grid)

    print("[load_dataset] Loading atts examples...")
    for (att_group_key, fp) in train.ANNOTATIONS_ATTS_FPS:
        dataset = pickle.load(open(fp, "r"))
        for key in dataset:
            if not os.path.isfile(fp):
                print("[WARNING] Could not find annotations (atts) file '%s'" % (fp,))
            else:
                state_idx = dataset[key]["idx"]
                from_datetime = dataset[key]["from_datetime"]
                screenshot_rs = dataset[key]["screenshot_rs"]
                attributes = dataset[key][att_group_key]
                if not key in examples:
                    examples[key] = dataset_state_idx_to_example(state_idx, memory)
                examples[key].add_attributes(attributes)

    return examples.values()

def load_dataset_annotated_compressed():
    fp = train.ANNOTATIONS_COMPRESSED_FP
    assert os.path.isfile(fp)
    with gz.open(fp, "rb") as f:
        examples = pickle.load(f)
    return examples

def load_dataset_autogen(val, nb_load, not_in=None):
    not_in = not_in if not_in is not None else set()

# Path: lib/replay_memory.py
# class ReplayMemory(object):
#     def __init__(self, filepath, max_size, max_size_tolerance):
#     def create_instance_supervised(val=False):
#     def create_instance_reinforced(val=False):
#     def create_instance_by_config(cfg_name):
#     def add_states(self, states, shrink=True):
#     def add_state(self, state, commit=True, shrink=True):
#     def update_state(self, idx, state, commit=True):
#     def get_state_by_id(self, idx):
#     def get_states_by_ids(self, ids):
#     def get_random_states(self, count):
#     def get_states_range(self, pos_start, length):
#     def get_random_state_chain(self, length, from_pos_range=None):
#     def get_random_state_chain_timediff(self, length, max_timediff_ms=500, depth=50):
#     def update_caches(self):
#     def is_above_tolerance(self):
#     def shrink_to_max_size(self, force=False):
#     def commit(self):
#     def close(self):
#     def connect(self):
# 
# Path: lib/util.py
# def template_match(needle, haystack):
# def compress_to_jpg(img):
# def compress_img(img, method):
# def decompress_img(img_compressed):
# def draw_image(img, other_img, x, y, copy=True, raise_if_oob=False):
# def draw_point(img, y, x, size=5, color=[255, 0, 0], alpha=1.0, copy=True):
# def draw_line(img, y1, x1, y2, x2, color=[0, 255, 0], alpha=1.0, thickness=1, clip_result=True, copy=True):
# def draw_direction_circle(img, y, x, r_inner, r_outer, angle_start, angle_end, color_border=[0, 255, 0], color_fill=[0, 200, 0], alpha=1.0):
# def draw_text(img, y, x, text, color=[0, 255, 0], size=25):
# def to_variable(inputs, volatile=False, requires_grad=True):
# def to_variables(inputs, volatile=False, requires_grad=True):
# def to_cuda(inputs, gpu=Config.GPU):
# def to_numpy(var):
# def draw_heatmap_overlay(img, heatmap, alpha=0.5):
# def create_2d_gaussian_old(size, fwhm=3, center=None):
# def create_2d_gaussian(size, sigma):
# FONT_CACHE = dict()


# Path: train_semisupervised/dataset.py
import sys
import os
import train
import numpy as np
import cPickle as pickle
import gzip as gz
import random
from lib import replay_memory
from lib import util

                    if not key in examples:
                        examples[key] = dataset_state_idx_to_example(state_idx, memory)
                    examples[key].add_grid(grid_key, grid)

    print("[load_dataset] Loading atts examples...")
    for (att_group_key, fp) in train.ANNOTATIONS_ATTS_FPS:
        dataset = pickle.load(open(fp, "r"))
        for key in dataset:
            if not os.path.isfile(fp):
                print("[WARNING] Could not find annotations (atts) file '%s'" % (fp,))
            else:
                state_idx = dataset[key]["idx"]
                from_datetime = dataset[key]["from_datetime"]
                screenshot_rs = dataset[key]["screenshot_rs"]
                attributes = dataset[key][att_group_key]
                if not key in examples:
                    examples[key] = dataset_state_idx_to_example(state_idx, memory)
                examples[key].add_attributes(attributes)

    return examples.values()

def load_dataset_annotated_compressed():
    fp = train.ANNOTATIONS_COMPRESSED_FP
    assert os.path.isfile(fp)
    with gz.open(fp, "rb") as f:
        examples = pickle.load(f)
    return examples

def load_dataset_autogen(val, nb_load, not_in=None):
    not_in = not_in if not_in is not None else set()

    memory = replay_memory.ReplayMemory.create_instance_supervised(val=val)