# Path: cufacesearch/cufacesearch/featurizer/generic_featurizer.py
# class GenericFeaturizer(ConfReader):
#   """Generic featurizer class every other featurizer should inherit from."""
# 
#   def __init__(self, global_conf_in, prefix=""):
#     super(GenericFeaturizer, self).__init__(global_conf_in, prefix)
# 
#   def featurize(self, img, bbox=None, img_type="scikit", sha1=None):
#     """This method takes an image (by default considering it was loaded from scikit)
#     and optionally an object (e.g. face) bounding box returned by a detector.
#     It generates a feature vector representing of the image or object.
#     An object or face `featurizer` has usually been trained on some specific type of detection,
#     so the same detector that has been used during training should be used to generate
#     the bounding box passed here."""
#     raise NotImplementedError("[{}:error] 'featurize' method was not overridden.".format(self.pp))
# 
# Path: cufacesearch/cufacesearch/common/dl.py
# def download_file(url, local_path):
#   """ Download file from `url` to the directory of `local_path`
# 
#   :param url: url of model to download
#   :type url: str
#   :param local_path: final local path of model
#   :type local_path: str
#   """
#   print "Downloading file from: {}".format(url)
#   out_dir = os.path.dirname(local_path)
#   try:
#     os.makedirs(out_dir)
#   except:
#     pass
#   urllib.request.urlretrieve(url, local_path, reporthook)


import os
import sys
import time
import numpy as np
import tensorflow as tf
from kaffetensorflow.network import Network
from scipy import misc
from .generic_featurizer import GenericFeaturizer
from ..common.dl import download_file
                              feed_dict={self.input_data: np.asarray([img.astype("float32")])})
    return output

class SentiBankTensorflowImgFeaturizer(GenericFeaturizer):

  def __init__(self, global_conf_in, prefix="SBTFIMGFEAT_"):
    super(SentiBankTensorflowImgFeaturizer, self).__init__(global_conf_in, prefix)
    if self.verbose > 0:
      print "[{}.log] global_conf: {}".format(self.pp, self.global_conf)

    # could be loaded from conf
    self.output_blobs = ['fc7']

    self.net = None
    self.transformer = None
    self.dir_path = os.path.dirname(os.path.realpath(__file__))

    print self.global_conf
    sys.stdout.flush()

    # Get sentibank tf model and imagenet mean
    self.model_path = self.get_required_param('model_path')
    # Test if file exits there
    if not os.path.exists(self.model_path):
      # Download file if not
      download_file(tfsentibank_npy_urldlpath, self.model_path)
    self.imgnetmean_path = self.get_required_param('imgmean_path')
    # Test if file exits there
    if not os.path.exists(self.imgnetmean_path):
      # Download file if not

# Path: cufacesearch/cufacesearch/featurizer/generic_featurizer.py
# class GenericFeaturizer(ConfReader):
#   """Generic featurizer class every other featurizer should inherit from."""
# 
#   def __init__(self, global_conf_in, prefix=""):
#     super(GenericFeaturizer, self).__init__(global_conf_in, prefix)
# 
#   def featurize(self, img, bbox=None, img_type="scikit", sha1=None):
#     """This method takes an image (by default considering it was loaded from scikit)
#     and optionally an object (e.g. face) bounding box returned by a detector.
#     It generates a feature vector representing of the image or object.
#     An object or face `featurizer` has usually been trained on some specific type of detection,
#     so the same detector that has been used during training should be used to generate
#     the bounding box passed here."""
#     raise NotImplementedError("[{}:error] 'featurize' method was not overridden.".format(self.pp))
# 
# Path: cufacesearch/cufacesearch/common/dl.py
# def download_file(url, local_path):
#   """ Download file from `url` to the directory of `local_path`
# 
#   :param url: url of model to download
#   :type url: str
#   :param local_path: final local path of model
#   :type local_path: str
#   """
#   print "Downloading file from: {}".format(url)
#   out_dir = os.path.dirname(local_path)
#   try:
#     os.makedirs(out_dir)
#   except:
#     pass
#   urllib.request.urlretrieve(url, local_path, reporthook)


# Path: cufacesearch/cufacesearch/featurizer/sbtf_img_featurizer.py
import os
import sys
import time
import numpy as np
import tensorflow as tf
from kaffetensorflow.network import Network
from scipy import misc
from .generic_featurizer import GenericFeaturizer
from ..common.dl import download_file

                              feed_dict={self.input_data: np.asarray([img.astype("float32")])})
    return output

class SentiBankTensorflowImgFeaturizer(GenericFeaturizer):

  def __init__(self, global_conf_in, prefix="SBTFIMGFEAT_"):
    super(SentiBankTensorflowImgFeaturizer, self).__init__(global_conf_in, prefix)
    if self.verbose > 0:
      print "[{}.log] global_conf: {}".format(self.pp, self.global_conf)

    # could be loaded from conf
    self.output_blobs = ['fc7']

    self.net = None
    self.transformer = None
    self.dir_path = os.path.dirname(os.path.realpath(__file__))

    print self.global_conf
    sys.stdout.flush()

    # Get sentibank tf model and imagenet mean
    self.model_path = self.get_required_param('model_path')
    # Test if file exits there
    if not os.path.exists(self.model_path):
      # Download file if not
      download_file(tfsentibank_npy_urldlpath, self.model_path)
    self.imgnetmean_path = self.get_required_param('imgmean_path')
    # Test if file exits there
    if not os.path.exists(self.imgnetmean_path):
      # Download file if not

      download_file(imagenet_mean_npy_urldlpath, self.imgnetmean_path)