如何加载.pb vgg16训练模型

时间:2020-03-08 12:03:37

标签: python tensorflow keras pytorch pickle

我正在尝试通过以下代码加载经过训练的模型,用于保存在本地设备上的图像美化:

# load network
network_pkl = misc.locate_network_pkl(args.results_dir)
print('Loading network from "%s"...' % network_pkl)
G, D, Gs = misc.load_network_pkl(args.results_dir, None)



def load_network_pkl(run_id_or_result_subdir_or_network_pkl, snapshot=None):
    return load_pkl(locate_network_pkl(run_id_or_result_subdir_or_network_pkl, snapshot))


def load_pkl(filename):
    with open(filename, 'rb') as file:
         return legacy.LegacyUnpickler(file, encoding='latin').load()

def save_pkl(obj, filename):
    with open(filename, 'wb') as file:
        pickle.dump(obj, file, protocol=pickle.HIGHEST_PROTOCOL)

我得到如下错误:

初始化TensorFlow ...正在从加载网络 “ C:\ Users \ wissa \ Desktop \ Out-source-projects / vgg_tf.pb” ...追溯 (最近一次通话最近):文件“ beautify_image.py”,第46行,位于 G,D,Gs = misc.load_network_pkl(args.results_dir,None)文件“ C:\ Users \ wissa \ Desktop \ Out-source-projects \ Beholder-GAN-master \ misc.py”, 在load_network_pkl中的第674行 返回load_pkl(locate_network_pkl(run_id_or_result_subdir_or_network_pkl, 快照))文件 “ C:\ Users \ wissa \ Desktop \ Out-source-projects \ Beholder-GAN-master \ misc.py”, 第436行,在load_pkl中 返回pickle.load(文件) _pickle.UnpicklingError:无效的加载键“,”。

您能帮我修复它吗?

0 个答案:

没有答案