douchi1945 2018-08-21 22:05
浏览 80

我可以在Golang中加载经过Python训练的分类器吗?

I am trying to load a python trained classifier in a Golang server.

In python, I generally do that:

classifier = pickle.load( open("classifier1.p", "rb"))

Is there any equivalent in Golang?

It took me 3 days to train the data and I can't wait again. So I tried to convert the classifier1.p to JSON format using this code.

fpkl = pickle.load( open("whatever/classifier1.p", "rb"))
fjson = open("whatever/classifier.json", "w")
json.dump(fpkl, fjson, ensure_ascii=False, sort_keys=True, indent=4)

An error occured: Object of type 'Pipeline' is not JSON serializable

I need some advice. Is there any Golang equivalent for my first problem? If there isn't, what can I do to avoid the data training again?

Thanks in advance.

  • 写回答

1条回答 默认 最新

  • dongzhuange2625 2018-08-22 00:31
    关注

    The documentation for the Python pickle library notes:

    The data format used by pickle is Python-specific. This [...] means that non-Python programs may not be able to reconstruct pickled Python objects.

    In principle you could read back the format (it's "just" a byte stream representing an object graph) and assign some meaning to the Python class name references in the pickle file. This would be highly specific to the specific object format you're reading back.

    My gut feel is that if it would take you 3 days to re-train your model using either Go-native tools or export it into a more neutral format, that will probably be faster and less frustrating than trying to decode the pickle file.

    评论

报告相同问题?

悬赏问题

  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致