Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

protobuf/init.lua:669: bad argument #1 to 'ReadTag' (string expected, got userdata) #3

Open
arashno opened this issue May 20, 2016 · 4 comments

Comments

@arashno
Copy link

arashno commented May 20, 2016

Hi all,
I have an LMDB which is created in python.
Each record is a protobuffer message.
I am trying to decode the messages by doing this:

key,value=cursor:get() local record = Record_pb.Record() record:ParseFromString(value)

The 'value' is a Tensor of Bytes.
and it gives me the following error. What should I do?

.../install/bin/luajit: .../torch/install/share/lua/5.1/protobuf/init.lua:669: bad argument #1 to 'ReadTag' (string expected, got userdata)
stack traceback:
[C]: in function 'ReadTag'
.../torch/install/share/lua/5.1/protobuf/init.lua:669: in function '_internal_parse'
.../torch/install/share/lua/5.1/protobuf/init.lua:687: in function 'merge_from_string'
.../torch/install/share/lua/5.1/protobuf/init.lua:696: in function 'ParseFromString'
LuaRead.lua:17: in main chunk
[C]: in function 'dofile'
...ouzz/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:145: in main chunk
[C]: at 0x00405800

@djungelorm
Copy link
Owner

djungelorm commented May 21, 2016

Looks like you are passing a value of type userdata to ParseFromString but it expects a Lua string. I guess you need to convert this userdata value to a string first? Not sure what you mean by a tensor of bytes (I've no experience with LMDB)

@arashno
Copy link
Author

arashno commented May 22, 2016

That's true.
By a tensor of bytes I mean a Torch's ByteTensor.
I read a tensor of bytes from DB (an array of bytes), Is there any fast tool to convert it to a string?
Thanks

@djungelorm
Copy link
Owner

There's nothing built into Lua unfortunately. I think the quickest way would be something like:

function FastBytesToString(bytes)
  s = {}
  for i = 1, getn(bytes) do
    s[i] = strchar(bytes[i])
  end
  return concat(s)
end

Found it on here: http://lua-users.org/lists/lua-l/2002-03/msg00166.html

@arashno
Copy link
Author

arashno commented May 23, 2016

I tried that, it works but it makes my program very slow.
Now my problem is a little bit different.
Now I can read a string from the DB.

This is my prototxt file:

message Record{

optional int32 channels = 1;
optional int32 height = 2;
optional int32 width = 3;
// the actual image data, in bytes
required bytes data = 4;
required int32 label = 5;
optional int32 count = 6;
optional float standing = 7;
optional float resting = 8;
optional float moving = 9;
optional float eating = 10;
optional float interacting = 11;
optional float babies = 12;
}

The problem is about 'data' field.
I read a string, call the ParseFromString method on it and I expect a tensor of bytes as the 'data' field but it gives me another string.
I have to convert back the string into a tensor of bytes and it makes my program very slow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants