# Path: selfsup/multi/loaders/loader.py
# class Loader:
#     def __init__(self, batch_size=16, num_threads=5):
#         self._batch_size = batch_size
#         self._num_threads = num_threads
# 
#     def batch(self):
#         raise NotImplemented('Cannot use base class')
# 
#     def start(self, sess):
#         pass


from .loader import Loader
import tensorflow as tf
import threading
import numpy as np
import time
import glob
import os
import imageio
import cv2
import deepdish as dd

SAMPLES_PER_VIDEO = 5
SAMPLES_PER_FRAME = 10
FRAMES = 4

MIN_QUEUE_SIZE = 250

def pad(x, min_side):
    if np.min(x.shape[:2]) >= min_side:
        return x
    else:
        sh = (max(min_side, x.shape[0]), max(min_side, x.shape[1])) + x.shape[2:]
        new_x = np.zeros(sh, dtype=x.dtype)
        new_x[:x.shape[0], :x.shape[1]] = x
        return new_x


def extract_optical_flow(fn, times, frames=8, scale_factor=1.0):
    cap = cv2.VideoCapture(fn)
    if not cap.isOpened():
        return []
    n_frames = cap.get(cv2.CAP_PROP_FRAME_COUNT)
    outputs = []
    if n_frames < frames * 2:
        return outputs


# Path: selfsup/multi/loaders/loader.py
# class Loader:
#     def __init__(self, batch_size=16, num_threads=5):
#         self._batch_size = batch_size
#         self._num_threads = num_threads
# 
#     def batch(self):
#         raise NotImplemented('Cannot use base class')
# 
#     def start(self, sess):
#         pass


# Path: selfsup/multi/loaders/video_avi_flow.py
from .loader import Loader
import tensorflow as tf
import threading
import numpy as np
import time
import glob
import os
import imageio
import cv2
import deepdish as dd


SAMPLES_PER_VIDEO = 5
SAMPLES_PER_FRAME = 10
FRAMES = 4

MIN_QUEUE_SIZE = 250

def pad(x, min_side):
    if np.min(x.shape[:2]) >= min_side:
        return x
    else:
        sh = (max(min_side, x.shape[0]), max(min_side, x.shape[1])) + x.shape[2:]
        new_x = np.zeros(sh, dtype=x.dtype)
        new_x[:x.shape[0], :x.shape[1]] = x
        return new_x


def extract_optical_flow(fn, times, frames=8, scale_factor=1.0):
    cap = cv2.VideoCapture(fn)
    if not cap.isOpened():
        return []
    n_frames = cap.get(cv2.CAP_PROP_FRAME_COUNT)
    outputs = []
    if n_frames < frames * 2:
        return outputs


    def resize(im):