def generate(self): model_path = os.path.expanduser(self.model_path) assert model_path.endswith('.h5'), 'Keras model or weights must be a .h5 file.' #---------------------------# # 载入模型与权值 #---------------------------# self.model = siamese(self.input_shape) self.model.load_weights(self.model_path) print('{} model loaded.'.format(model_path))
def generate(self): model_path = os.path.expanduser(self.model_path) assert model_path.endswith( '.h5'), 'Keras model or weights must be a .h5 file.' self.model = siamese(self.input_shape) self.model.load_weights(self.model_path) self.model.summary() print('{} model, anchors, and classes loaded.'.format(model_path))
def generate(self): print('Loading weights into state dict...') device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') model = siamese(self.input_shape) model.load_state_dict(torch.load(self.model_path, map_location=device)) self.net = model.eval() print('{} model, anchors, and classes loaded.'.format(self.model_path)) if self.cuda: self.net = torch.nn.DataParallel(self.net) cudnn.benchmark = True self.net = self.net.cuda()
dataset_path = "datasets" #----------------------------------------------------# # 训练好的权值保存在logs文件夹里面 #----------------------------------------------------# log_dir = "logs/" #----------------------------------------------------# # 输入图像的大小,默认为105,105,3 #----------------------------------------------------# input_shape = [105,105,3] #----------------------------------------------------# # 训练自己的数据的话需要把train_own_data设置成true # 训练自己的数据和训练omniglot数据格式不一样 #----------------------------------------------------# train_own_data = False model = siamese(input_shape) #------------------------------------------------------# # 权值文件请看README,百度网盘下载 #------------------------------------------------------# model_path = 'model_data/vgg16_weights_tf_dim_ordering_tf_kernels_notop.h5' model.load_weights(model_path, by_name=True, skip_mismatch=True) #-------------------------------------------------------------------------------# # 训练参数的设置 # logging表示tensorboard的保存地址 # checkpoint用于设置权值保存的细节,period用于修改多少epoch保存一次 # reduce_lr用于设置学习率下降的方式 # early_stopping用于设定早停,val_loss多次不下降自动结束训练,表示模型基本收敛 #-------------------------------------------------------------------------------# tensorboard = TensorBoard(log_dir=log_dir) checkpoint_period = ModelCheckpoint(log_dir + 'ep{epoch:03d}-loss{loss:.3f}-val_loss{val_loss:.3f}.h5',