Python config.DEFAULT_MODEL_PATH Examples

The following are 14 code examples of config.DEFAULT_MODEL_PATH(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module config , or try the search function .
Example #1
Source File: model.py    From MAX-Question-Answering with Apache License 2.0 6 votes vote down vote up
def __init__(self, path=DEFAULT_MODEL_PATH):
        logger.info('Loading model from: {}...'.format(path))

        # Parameters for inference (need to be the same values the model was trained with)
        self.max_seq_length = 512
        self.doc_stride = 128
        self.max_query_length = 64
        self.max_answer_length = 30

        # Initialize the tokenizer
        self.tokenizer = FullTokenizer(
            vocab_file='assets/vocab.txt', do_lower_case=True)

        self.predict_fn = predictor.from_saved_model(DEFAULT_MODEL_PATH)

        logger.info('Loaded model') 
Example #2
Source File: model.py    From MAX-Image-Colorizer with Apache License 2.0 6 votes vote down vote up
def __init__(self, path=DEFAULT_MODEL_PATH):
        logger.info('Loading model from: {}...'.format(path))
        sess = tf.Session(graph=tf.Graph())
        # Load the graph
        model_graph_def = sm.loader.load(sess, [sm.tag_constants.SERVING], path)
        sig_def = model_graph_def.signature_def[sm.signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY]

        input_name = sig_def.inputs['input_images'].name
        output_name = sig_def.outputs['output_images'].name

        # Set up instance variables and required inputs for inference
        self.sess = sess
        self.model_graph_def = model_graph_def
        self.output_tensor = sess.graph.get_tensor_by_name(output_name)
        self.input_name = input_name
        self.output_name = output_name
        logger.info('Loaded model') 
Example #3
Source File: model.py    From MAX-Image-Caption-Generator with Apache License 2.0 5 votes vote down vote up
def __init__(self, path=DEFAULT_MODEL_PATH):
        # TODO Replace this part with SavedModel
        g = tf.Graph()
        with g.as_default():
            model = inference_wrapper.InferenceWrapper()
            restore_fn = model.build_graph_from_config(configuration.ModelConfig(),
                                                       path)
        g.finalize()
        self.model = model
        sess = tf.Session(graph=g)
        # Load the model from checkpoint.
        restore_fn(sess)
        self.sess = sess 
Example #4
Source File: model.py    From MAX-ResNet-50 with Apache License 2.0 5 votes vote down vote up
def __init__(self, path=DEFAULT_MODEL_PATH):
        logger.info('Loading model from: {}...'.format(path))
        clear_session()
        self.model = models.load_model(
            os.path.join(path, 'resnet50.h5'))
        # this seems to be required to make Keras models play nicely with threads
        self.model._make_predict_function()
        logger.info('Loaded model: {}'.format(self.model.name))
        with open(os.path.join(DEFAULT_MODEL_PATH,
                  'class_index.json')) as class_file:
            self.classes = json.load(class_file) 
Example #5
Source File: model.py    From MAX-Text-Summarizer with Apache License 2.0 5 votes vote down vote up
def __init__(self, path=DEFAULT_MODEL_PATH):
        logger.info('Loading model from: %s...', path)

        self.log_dir = TemporaryDirectory()
        self.p_summarize = Popen(['python', 'core/getpoint/run_summarization.py', '--mode=decode',  # nosec - B603
                                  '--ckpt_dir={}'.format(ASSET_DIR),
                                  '--vocab_path={}'.format(DEFAULT_VOCAB_PATH),
                                  '--log_root={}'.format(self.log_dir.name)],
                                 stdin=PIPE, stdout=PIPE) 
Example #6
Source File: model.py    From MAX-Named-Entity-Tagger with Apache License 2.0 5 votes vote down vote up
def __init__(self, path=DEFAULT_MODEL_PATH):
        logger.info('Loading model from: {}...'.format(path))

        # load assets first to enable model definition
        self._load_assets(path)

        # Loading the tf SavedModel
        self.graph = tf.Graph()
        self.sess = tf.Session(graph=self.graph)
        tf.saved_model.loader.load(self.sess, [tag_constants.SERVING], DEFAULT_MODEL_PATH)

        self.word_ids_tensor = self.sess.graph.get_tensor_by_name('word_input:0')
        self.char_ids_tensor = self.sess.graph.get_tensor_by_name('char_input:0')
        self.output_tensor = self.sess.graph.get_tensor_by_name('predict_output/truediv:0') 
Example #7
Source File: model.py    From MAX-Skeleton with Apache License 2.0 5 votes vote down vote up
def __init__(self, path=DEFAULT_MODEL_PATH):
        logger.info('Loading model from: {}...'.format(path))

        # Load the graph

        # Set up instance variables and required inputs for inference

        logger.info('Loaded model') 
Example #8
Source File: model.py    From MAX-Weather-Forecaster with Apache License 2.0 5 votes vote down vote up
def __init__(self, path=DEFAULT_MODEL_PATH):

        logger.info('Loading models from: {}...'.format(path))
        self.models = {}
        for model in MODELS:
            logger.info('Loading model: {}'.format(model))
            self.models[model] = SingleModelWrapper(model=model, path=path)

        logger.info('Loaded all models') 
Example #9
Source File: model.py    From MAX-Toxic-Comment-Classifier with Apache License 2.0 5 votes vote down vote up
def __init__(self, path=DEFAULT_MODEL_PATH):
        """Instantiate the BERT model."""
        logger.info('Loading model from: {}...'.format(path))

        # Load the model
        # 1. set the appropriate parameters
        self.eval_batch_size = 64
        self.max_seq_length = 256
        self.do_lower_case = True

        # 2. Initialize the PyTorch model
        model_state_dict = torch.load(DEFAULT_MODEL_PATH+'pytorch_model.bin', map_location='cpu')
        self.tokenizer = BertTokenizer.from_pretrained(DEFAULT_MODEL_PATH, do_lower_case=self.do_lower_case)
        self.model = BertForMultiLabelSequenceClassification.from_pretrained(DEFAULT_MODEL_PATH,
                                                                             num_labels=len(LABEL_LIST),
                                                                             state_dict=model_state_dict)
        self.device = torch.device("cpu")
        self.model.to(self.device)

        # 3. Set the layers to evaluation mode
        self.model.eval()

        logger.info('Loaded model') 
Example #10
Source File: model.py    From MAX-Review-Text-Generator with Apache License 2.0 5 votes vote down vote up
def __init__(self, path=DEFAULT_MODEL_PATH, model_file=DEFAULT_MODEL_FILE):
        logger.info('Loading model from: {}...'.format(path))
        model_path = '{}/{}'.format(path, model_file)
        clear_session()
        self.graph = tf.Graph()
        with self.graph.as_default():
            self.model = models.load_model(model_path)
            logger.info('Loaded model: {}'.format(self.model.name))
        self._load_assets(path) 
Example #11
Source File: model.py    From MAX-Image-Resolution-Enhancer with Apache License 2.0 5 votes vote down vote up
def __init__(self, path=DEFAULT_MODEL_PATH):
        logger.info('Loading model from: {}...'.format(path))

        # Initialize the SRGAN controller
        self.SRGAN = SRGAN_controller(checkpoint=DEFAULT_MODEL_PATH)

        logger.info('Loaded model') 
Example #12
Source File: model.py    From MAX-Breast-Cancer-Mitosis-Detector with Apache License 2.0 5 votes vote down vote up
def __init__(self, path=DEFAULT_MODEL_PATH):
        logger.info('Loading model from: {}...'.format(path))
        self.sess = tensorflow.keras.backend.get_session()
        base_model = tensorflow.keras.models.load_model(path, compile=False)
        probs = tensorflow.keras.layers.Activation('sigmoid', name="sigmoid")(base_model.output)
        self.model = tensorflow.keras.models.Model(inputs=base_model.input, outputs=probs)
        self.input_tensor = self.model.input
        self.output_tensor = self.model.output 
Example #13
Source File: model.py    From MAX-Text-Sentiment-Classifier with Apache License 2.0 5 votes vote down vote up
def __init__(self, path=DEFAULT_MODEL_PATH):
        logger.info('Loading model from: {}...'.format(path))

        self.max_seq_length = 128
        self.do_lower_case = True

        # Set Logging verbosity
        tf.logging.set_verbosity(tf.logging.INFO)

        # Loading the tf Graph
        self.graph = tf.Graph()
        self.sess = tf.Session(graph=self.graph)
        tf.saved_model.loader.load(self.sess, [tag_constants.SERVING], DEFAULT_MODEL_PATH)

        # Validate init_checkpoint
        tokenization.validate_case_matches_checkpoint(self.do_lower_case,
                                                      DEFAULT_MODEL_PATH)

        # Initialize the dataprocessor
        self.processor = MAXAPIProcessor()

        # Get the labels
        self.label_list = self.processor.get_labels()

        # Initialize the tokenizer
        self.tokenizer = tokenization.FullTokenizer(
            vocab_file=f'{DEFAULT_MODEL_PATH}/vocab.txt', do_lower_case=self.do_lower_case)

        logger.info('Loaded model') 
Example #14
Source File: model.py    From MAX-Sports-Video-Classifier with Apache License 2.0 5 votes vote down vote up
def __init__(self, path=DEFAULT_MODEL_PATH, model_dir=DEFAULT_MODEL_DIR):
        logger.info('Loading model from: {}...'.format(path))
        sess = tf.Session(graph=tf.Graph())
        # load the graph
        saved_model_path = '{}/{}'.format(path, model_dir)
        model_graph_def = tf.saved_model.load(sess, [tf.saved_model.tag_constants.SERVING], saved_model_path)
        sig_def = model_graph_def.signature_def[tf.saved_model.signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY]

        input_name = sig_def.inputs['inputs'].name
        output_name = sig_def.outputs['scores'].name

        # Load labels from file
        label_file = codecs.open('./{}/labels.txt'.format(path), "r", encoding="utf-8")
        labels = [label.strip('\n') for label in label_file.readlines()]

        self.labels = labels

        # set up instance variables and required inputs for inference
        self.sess = sess
        self.model_graph_def = model_graph_def
        self.output_tensor = sess.graph.get_tensor_by_name(output_name)
        self.input_name = input_name
        self.output_name = output_name

        self.means = np.load('./{}/crop_mean.npy'.format(path)).reshape(
            [NUM_FRAMES_PER_CLIP, CROP_SIZE, CROP_SIZE, CHANNELS])
        logger.info('Loaded model')