Ejemplo n.º 1
0
    def __init__(self, model_url=USE_URL):
        if "TFHUB_CACHE_DIR" in os.environ:
            tfdata = os.environ['TFHUB_CACHE_DIR']
            model_url= tfdata + "/" + cachedir
#             model_url = tfdata
            print(tfdata)
        else:
            print("TFHUB_CACHE_DIR=None")

        graph = Graph()
        with graph.as_default():
            embed = hub.Module(model_url)
            self.sentences = tf.placeholder(dtype=tf.string, shape=[None])
            self.encoded_text = tf.cast(embed(self.sentences), tf.float32)
            init_op = tf.group([tf.global_variables_initializer(), tf.tables_initializer()])
        graph.finalize()

        self.session = tf.Session(graph=graph)
        self.session.run(init_op)
Ejemplo n.º 2
0
    def create_detector(self, verbose, mtcnn_kwargs):
        """ Create the mtcnn detector """
        self.verbose = verbose

        if self.verbose:
            print("Adding MTCNN detector")

        self.kwargs = mtcnn_kwargs

        mtcnn_graph = Graph()
        with mtcnn_graph.as_default():
            mtcnn_session = Session()
            with mtcnn_session.as_default():
                pnet, rnet, onet = create_mtcnn(mtcnn_session, self.data_path)
        mtcnn_graph.finalize()

        self.kwargs["pnet"] = pnet
        self.kwargs["rnet"] = rnet
        self.kwargs["onet"] = onet
        self.initialized = True
Ejemplo n.º 3
0
    def load_model(self, verbose, dummy, ratio):
        """ Load the Keras Model """
        self.verbose = verbose
        if self.verbose:
            print("Initializing keras model...")

        keras_graph = Graph()
        with keras_graph.as_default():
            config = ConfigProto()
            if ratio:
                config.gpu_options.per_process_gpu_memory_fraction = ratio
            self.session = Session(config=config)
            with self.session.as_default():
                self.model = keras.models.load_model(
                    self.model_path,
                    custom_objects={'TorchBatchNorm2D': TorchBatchNorm2D})
                self.model.predict(dummy)
        keras_graph.finalize()

        self.initialized = True
Ejemplo n.º 4
0
    def create_detector(self, verbose, mtcnn_kwargs):
        """ Create the mtcnn detector """
        self.verbose = verbose

        if self.verbose:
            print("Adding MTCNN detector")

        self.kwargs = mtcnn_kwargs

        mtcnn_graph = Graph()
        with mtcnn_graph.as_default():
            mtcnn_session = Session()
            with mtcnn_session.as_default():
                pnet, rnet, onet = create_mtcnn(mtcnn_session, self.data_path)
        mtcnn_graph.finalize()

        self.kwargs["pnet"] = pnet
        self.kwargs["rnet"] = rnet
        self.kwargs["onet"] = onet
        self.initialized = True
Ejemplo n.º 5
0
    def load_model(self, verbose, dummy, ratio):
        """ Load the Keras Model """
        self.verbose = verbose
        if self.verbose:
            print("Initializing keras model...")

        keras_graph = Graph()
        with keras_graph.as_default():
            config = ConfigProto()
            if ratio:
                config.gpu_options.per_process_gpu_memory_fraction = ratio
            self.session = Session(config=config)
            with self.session.as_default():
                self.model = keras.models.load_model(
                    self.model_path,
                    custom_objects={'TorchBatchNorm2D':
                                    TorchBatchNorm2D})
                self.model.predict(dummy)
        keras_graph.finalize()

        self.initialized = True