无法在julia中释放python pickle对象
TypeError(“需要一个类似字节的对象,而不是'str'”)
#download("http://www.cs.utoronto.ca/~kriz/cifar-10-python.tar.gz","imgs_dataset.tar.gz")
#cmd = `tar xvzf imgs_dataset.tar.gz`
#run(cmd)
using PyCall
using StatsBase
@pyimport pickle
mainDir="./cifar-10-batches-py/"
function read_data(mainDir)
dict=[]
open(mainDir*"data_batch_1","r") do f
dict = pickle.load(f)
end
return dict
end
dict = read_data(mainDir)
imgs = dict["data"];
classes = dict["labels"];
X=float.(imgs)';
Y=onehotbatch(classes,0:9);
我评论了前3行,因为我之前已经运行过它们,所以我的互联网连接大约需要2个小时才能下载CIFAR-10
我收到以下错误:
PyError($(Expr(:escape,:(ccall(#= /home/remon/.julia/packages/PyCall/0jMpb/src/pyfncall.jl:44 =# @pysym(:PyObject_Call),PyPtr,(PyPtr,PyPtr,PyPtr),o,pyargsptr, kw)))))TypeError(“类似字节的对象是 必需,而不是'str'“,)
注意:
那是什么问题?
答案 0 :(得分:1)
这是一个示例Julia会话,可以满足您的所有需求:
julia> using PyCall
julia> @pyimport pickle
julia> x = [1,2,3];
julia> f = pybuiltin("open")("file.pickle","wb")
PyObject <_io.BufferedWriter name='file.pickle'>
julia> p = pickle.Pickler(f)
PyObject <_pickle.Pickler object at 0x000000003DDABC28>
julia> p[:dump](x)
julia> f[:close]()
julia> f = pybuiltin("open")("file.pickle","rb")
PyObject <_io.BufferedReader name='file.pickle'>
julia> p = pickle.Unpickler(f)
PyObject <_pickle.Unpickler object at 0x000000003DE1C5C0>
julia> y=p[:load]()
3-element Array{Int64,1}:
1
2
3
julia> f[:close]()