當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。