【问题标题】:How to convert .npy file into .binaryproto?如何将 .npy 文件转换为 .binaryproto?
【发布时间】:2017-05-21 01:56:08
【问题描述】:

我使用 python 创建了一个平均图像文件并将其保存到 numpy 文件中。我想知道如何将这个 .npy 文件转换为 .binaryproto 文件。我正在使用这个文件来使用 GoogLeNet 进行训练。

【问题讨论】:

  • 你可以找到答案here

标签: python c++ caffe


【解决方案1】:

您可以简单地使用 numpy 创建 .binaryproto 和给定的 caffe io 函数

import caffe
#avg_img is your numpy array with the average data 
blob = caffe.io.array_to_blobproto( avg_img)
with open( mean.binaryproto, 'wb' ) as f :
    f.write( blob.SerializeToString())

【讨论】:

    【解决方案2】:

    这是@Kev1n91 代码的改进版本。

    import caffe
    import numpy as np
    
    mean_npy = np.load('mean.npy') # Input numpy array
    blob = caffe.io.array_to_blobproto(mean_npy)
    mean_binproto = 'mean.binaryproto' # Output binaryproto file
    with open(mean_binproto, 'wb') as f :
        f.write( blob.SerializeToString())
    

    【讨论】:

      猜你喜欢
      • 2022-11-10
      • 2019-09-10
      • 2019-02-18
      • 1970-01-01
      • 2022-11-01
      • 2023-01-10
      • 2022-10-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多