当前位置: 首页>>代码示例>>Python>>正文


Python generic_utils.CustomObjectScope方法代码示例

本文整理汇总了Python中keras.utils.generic_utils.CustomObjectScope方法的典型用法代码示例。如果您正苦于以下问题:Python generic_utils.CustomObjectScope方法的具体用法?Python generic_utils.CustomObjectScope怎么用?Python generic_utils.CustomObjectScope使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在keras.utils.generic_utils的用法示例。


在下文中一共展示了generic_utils.CustomObjectScope方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from keras.utils import generic_utils [as 别名]
# 或者: from keras.utils.generic_utils import CustomObjectScope [as 别名]
def __init__(self, nb_classes, resnet_layers, input_shape, weights):
        self.input_shape = input_shape
        self.num_classes = nb_classes

        json_path = join("weights", "keras", weights + ".json")
        h5_path = join("weights", "keras", weights + ".h5")
        if 'pspnet' in weights:
            if os.path.isfile(json_path) and os.path.isfile(h5_path):
                print("Keras model & weights found, loading...")
                with CustomObjectScope({'Interp': layers.Interp}):
                    with open(json_path) as file_handle:
                        self.model = model_from_json(file_handle.read())
                self.model.load_weights(h5_path)
            else:
                print("No Keras model & weights found, import from npy weights.")
                self.model = layers.build_pspnet(nb_classes=nb_classes,
                                                 resnet_layers=resnet_layers,
                                                 input_shape=self.input_shape)
                self.set_npy_weights(weights)
        else:
            print('Load pre-trained weights')
            self.model = load_model(weights) 
开发者ID:Vladkryvoruchko,项目名称:PSPNet-Keras-tensorflow,代码行数:24,代码来源:pspnet.py

示例2: initialize_celeb

# 需要导入模块: from keras.utils import generic_utils [as 别名]
# 或者: from keras.utils.generic_utils import CustomObjectScope [as 别名]
def initialize_celeb(self):
        print("Initializing celebrity network...")

        with CustomObjectScope({'relu6': keras.layers.ReLU(6.),
                                'DepthwiseConv2D': keras.layers.DepthwiseConv2D,
                                'lifted_struct_loss': lifted_struct_loss,
                                'triplet_loss': triplet_loss}):
            self.siameseNet = keras.models.load_model(os.path.join(self.siamesepath, "feature_model.h5"))

        self.siameseNet._make_predict_function()

        ##### Read celebrity features
        celebrity_features = self.siamesepath + os.sep + "features_" + self.celeb_dataset + ".h5"
        print("Reading celebrity data from {}...".format(celebrity_features))

        with h5py.File(celebrity_features, "r") as h5:
            celeb_features = np.array(h5["features"]).astype(np.float32)
            self.path_ends = list(h5["path_ends"])
            self.celeb_files = [os.path.join(self.visualization_path, s.decode("utf-8")) for s in self.path_ends]

        print("Building index...")
        self.celeb_index = faiss.IndexFlatL2(celeb_features.shape[1])
        self.celeb_index.add(celeb_features) 
开发者ID:mahehu,项目名称:TUT-live-age-estimator,代码行数:25,代码来源:RecognitionThread.py

示例3: run_model

# 需要导入模块: from keras.utils import generic_utils [as 别名]
# 或者: from keras.utils.generic_utils import CustomObjectScope [as 别名]
def run_model(i,X_test):
    score = np.zeros((5, len(X_test)))
    with CustomObjectScope({'Attention': Attention}):
        model=load_model(curDir+ 'model/binding_model' + str(i+1)+ '.hdf5')
        score[i,:] =np.squeeze(model.predict_proba(X_test))
    return score[i,:] 
开发者ID:jiujiezz,项目名称:deephlapan,代码行数:8,代码来源:deephlapan_main.py

示例4: run_model1

# 需要导入模块: from keras.utils import generic_utils [as 别名]
# 或者: from keras.utils.generic_utils import CustomObjectScope [as 别名]
def run_model1(i,X_test):
    score1 = np.zeros((5, len(X_test)))
    with CustomObjectScope({'Attention': Attention}):
        model1=load_model(curDir+ 'model/immunogenicity_model' + str(i+1)+ '.hdf5')
        score1[i,:]=np.squeeze(model1.predict_proba(X_test))
    return score1[i,:] 
开发者ID:jiujiezz,项目名称:deephlapan,代码行数:8,代码来源:deephlapan_main.py

示例5: load_model

# 需要导入模块: from keras.utils import generic_utils [as 别名]
# 或者: from keras.utils.generic_utils import CustomObjectScope [as 别名]
def load_model(self):
        global Graph  # multiprocess-able

        config = tf.ConfigProto()
        config.gpu_options.allow_growth = True
        config.gpu_options.per_process_gpu_memory_fraction = 0.3
        set_session(tf.Session(config=config))

        # model.99-0.98.h5
        files = glob.glob('models/{}/model.*.h5'.format(self.model_name))

        if len(files) == 0:
            print('Trained model not found from "models/{}/model.*.h5"'.format(self.model_name))
            print('Building new model because model file not found...')

            return self.build_model(self.kernel, self.stride)

        last_file = max(files, key=os.path.getctime)

        file_name = last_file.replace('\\', '/').split('/')[-1].replace('model.', '').replace('.h5', '')
        self.epoch = int(file_name.split('-')[0])
        acc = float(file_name.split('-')[1])

        with CustomObjectScope({'relu6': tf.nn.relu6, 'DepthwiseConv2D': keras.layers.DepthwiseConv2D, 'tf': tf}):
            model = load_model(last_file)

        model.summary()

        Graph = tf.get_default_graph()

        print('Loaded last model - {}, epoch: {}, acc: {}'.format(last_file, self.epoch, acc))

        return model 
开发者ID:YoongiKim,项目名称:Walk-Assistant,代码行数:35,代码来源:model.py

示例6: __init__

# 需要导入模块: from keras.utils import generic_utils [as 别名]
# 或者: from keras.utils.generic_utils import CustomObjectScope [as 别名]
def __init__(self, parent, params):
        print("Initializing recognition thread...")
        threading.Thread.__init__(self)
        self.parent = parent

        ##### Initialize aligners for face alignment.
        aligner_path = params.get("recognition", "aligner")
        aligner_targets_path = params.get("recognition", "aligner_targets")
        self.aligner = keras.models.load_model(aligner_path)
        self.aligner._make_predict_function()
        self.aligner_input_shape = (self.aligner.input_shape[2], self.aligner.input_shape[1])

        # load targets
        aligner_targets = np.loadtxt(aligner_targets_path)
        left_eye = (aligner_targets[36] + aligner_targets[39]) / 2
        right_eye = (aligner_targets[42] + aligner_targets[45]) / 2
        nose = aligner_targets[30]
        left_mouth = aligner_targets[48]
        right_mouth = aligner_targets[54]
        # Dlib order
        #self.shape_targets = np.stack((left_eye, left_mouth, nose, right_eye, right_mouth))
        # CNN order
        self.shape_targets = np.stack((left_eye, right_eye, nose, left_mouth, right_mouth))

        ##### Initialize networks for Age, Gender and Expression
        ##### 1. AGE, GENDER, SMILE MULTITASK
        print("Initializing multitask network...")
        multitaskpath = params.get("recognition", "multitask_folder")
        with CustomObjectScope({'relu6': keras.layers.ReLU(6.),
                                'DepthwiseConv2D': keras.layers.DepthwiseConv2D}):
            self.multiTaskNet = keras.models.load_model(os.path.join(multitaskpath, 'model.h5'))
        self.multiTaskNet._make_predict_function()

        ##### Read class names
        self.expressions = {int(key): val for key, val in params['expressions'].items()}  # convert string key to int
        self.minDetections = int(params.get("recognition", "mindetections"))

        ##### 2. CELEBRITY
        self.siamesepaths = params['celebmodels']
        self.siamesepath = self.siamesepaths["0"]
        self.celeb_dataset = params.get("recognition", "celeb_dataset")
        self.visualization_path = params.get("recognition", "visualization_path")
        self.initialize_celeb()

        # Starting the thread
        self.switching_model = False
        self.recognition_running = False
        print("Recognition thread started...") 
开发者ID:mahehu,项目名称:TUT-live-age-estimator,代码行数:50,代码来源:RecognitionThread.py


注:本文中的keras.utils.generic_utils.CustomObjectScope方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。