當前位置: 首頁>>代碼示例>>Python>>正文


Python models.load_model方法代碼示例

本文整理匯總了Python中keras_retinanet.models.load_model方法的典型用法代碼示例。如果您正苦於以下問題:Python models.load_model方法的具體用法?Python models.load_model怎麽用?Python models.load_model使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在keras_retinanet.models的用法示例。


在下文中一共展示了models.load_model方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from keras_retinanet import models [as 別名]
# 或者: from keras_retinanet.models import load_model [as 別名]
def __init__(self):
        '''
            model = Detector()
        '''
        url = 'https://github.com/bedapudi6788/NudeNet/releases/download/v0/detector_model'
        home = os.path.expanduser("~")
        model_folder = os.path.join(home, '.NudeNet/')
        if not os.path.exists(model_folder):
            os.mkdir(model_folder)
        
        model_path = os.path.join(model_folder, 'detector')

        if not os.path.exists(model_path):
            print('Downloading the checkpoint to', model_path)
            pydload.dload(url, save_to_path=model_path, max_time=None)

        Detector.detection_model = models.load_model(model_path, backbone_name='resnet101') 
開發者ID:notAI-tech,項目名稱:NudeNet,代碼行數:19,代碼來源:detector.py

示例2: setUpClass

# 需要導入模塊: from keras_retinanet import models [as 別名]
# 或者: from keras_retinanet.models import load_model [as 別名]
def setUpClass(cls):
        print("******* Unit Test for RetinaNet *******")
        url = 'https://github.com/fizyr/keras-retinanet/releases/download/0.5.1/resnet50_coco_best_v2.1.0.h5'
        r = requests.get(url)

        with open('resnet50_coco_best_v2.1.0.h5', 'wb') as f:
            f.write(r.content)

        classes = json.load(open("nyoka/tests/categories_coco.json",'r'))
        cls.classes = list(classes.values())
        cls.adapa_utility = AdapaUtility()
        cls.model = load_model('resnet50_coco_best_v2.1.0.h5', backbone_name='resnet50') 
開發者ID:nyoka-pmml,項目名稱:nyoka,代碼行數:14,代碼來源:testScoreWithAdapaRetinaNet.py

示例3: setUpClass

# 需要導入模塊: from keras_retinanet import models [as 別名]
# 或者: from keras_retinanet.models import load_model [as 別名]
def setUpClass(cls):
        url = 'https://github.com/fizyr/keras-retinanet/releases/download/0.5.1/resnet50_coco_best_v2.1.0.h5'
        r = requests.get(url)

        with open('resnet50_coco_best_v2.1.0.h5', 'wb') as f:
            f.write(r.content)
        cls.model = load_model('resnet50_coco_best_v2.1.0.h5', backbone_name='resnet50') 
開發者ID:nyoka-pmml,項目名稱:nyoka,代碼行數:9,代碼來源:test_retinanet_to_pmml_UnitTest.py

示例4: _load_model_with_nms

# 需要導入模塊: from keras_retinanet import models [as 別名]
# 或者: from keras_retinanet.models import load_model [as 別名]
def _load_model_with_nms(self, test_args):
        """ This is mostly copied fomr retinanet.py """

        backbone_name = test_args.get('DETECTOR','backbone')
        print backbone_name
        print test_args.get('DETECTOR','detector_model_path')
        model = keras.models.load_model(
                str(test_args.get('DETECTOR','detector_model_path')),
                custom_objects=backbone(backbone_name).custom_objects
                )

        # compute the anchors
        features = [model.get_layer(name).output
                for name in ['P3', 'P4', 'P5', 'P6', 'P7']]
        anchors  = build_anchors(AnchorParameters.default, features)

        # we expect the anchors, regression and classification values as first
        # output
        print len(model.outputs)
        regression     = model.outputs[0]
        classification = model.outputs[1]
        print classification.shape[1]
        print regression.shape

        # "other" can be any additional output from custom submodels,
        # by default this will be []
        other = model.outputs[2:]

        # apply predicted regression to anchors
        boxes = layers.RegressBoxes(name='boxes')([anchors, regression])
        boxes = layers.ClipBoxes(name='clipped_boxes')([model.inputs[0], boxes])

        # filter detections (apply NMS / score threshold / select top-k)
        #detections = layers.FilterDetections(
        #        nms=True,
        #        name='filtered_detections',
        #        nms_threshold = test_args.getfloat('DETECTOR','nms_threshold'),
        #        score_threshold = test_args.getfloat('DETECTOR','det_threshold'),
        #        max_detections = test_args.getint('DETECTOR', 'max_detections')
        #        )([boxes, classification] + other)        
        detections = layers.filter_detections.filter_detections(
                boxes=boxes,
                classification=classification,
                other=other,
                nms=True,
                nms_threshold = test_args.getfloat('DETECTOR','nms_threshold'),
                score_threshold = test_args.getfloat('DETECTOR','det_threshold'),
                max_detections = test_args.getint('DETECTOR', 'max_detections')
                )

        outputs = detections

        # construct the model
        return keras.models.Model(
                inputs=model.inputs, outputs=outputs, name='retinanet-bbox') 
開發者ID:DLR-RM,項目名稱:AugmentedAutoencoder,代碼行數:57,代碼來源:aae_retina_pose_estimator.py

示例5: on_epoch_end

# 需要導入模塊: from keras_retinanet import models [as 別名]
# 或者: from keras_retinanet.models import load_model [as 別名]
def on_epoch_end(self, epoch):
        # load this epoch's saved snapshot
        model_path = '{backbone}_{dataset_type}_{epoch:02d}.h5'.format(
            backbone=self.snapshot_data['backbone'], dataset_type=self.snapshot_data['dataset_type'], epoch=(epoch+1))
        model_path = os.path.join(self.snapshot_data['path'], model_path)
        print('loading model {}, this may take a while ... '.format(model_path))
        self.model = models.load_model(model_path, convert=True, backbone_name=self.snapshot_data['backbone'], nms=False)
        
        # run a detection as classification on the model and our test dataset
        TP, FP = detection_as_classification(self.model, self.test_generator)
        precision = float(TP)/(len(self.test_generator)*self.batch_size)
        if TP+FP == 0:
            recall = -1
        else:
            recall = float(TP)/(TP+FP)

        my_file = Path(self.log_filename)

        # write header if this is the first run
        if not my_file.is_file():
            print("writing head")
            with open(self.log_filename, "w") as log:
                log.write("datetime,epoch,precision,recall\n")

        # append parameters
        with open(self.log_filename, "a") as log:
            log.write(datetime.datetime.now().strftime("%Y-%m-%d %H:%M"))
            log.write(',')
            log.write(str(epoch))
            log.write(',')
            log.write(str(precision))
            log.write(',')
            log.write(str(recall))
            log.write('\n')

        print('\nValidation set at {}:'.format(self.test_data_dir))
        print('Precision: {}% , Recall: {}% \n'.format(precision*100, recall*100))

        # remove snapshots, but save the last one
        if (not epoch >= self.num_epochs-1) and self.delete_model:
            os.remove(model_path)
        # make sure we don't run out of memory!
        del self.model
        gc.collect() 
開發者ID:921kiyo,項目名稱:3d-dl,代碼行數:46,代碼來源:train_keras_retinanet.py


注:本文中的keras_retinanet.models.load_model方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。