我有一个从URL使用luasocket下载图像Lua代码:转换二进制数据火炬张量在Lua
local http = require('socket.http')
local image = require('image')
image_url = 'https://www.somedomain.com/someimage.jpg'
local body, code = http.request(image_url) -- body has jpg binary data
if not body then error(code) end -- check for errors
为了把这个图像读到火炬张量,我把它保存在一个JPG文件并使用image.load
阅读:
-- open a file in binary mode to store the image
local f = assert(io.open('./temp.jpg', 'wb'))
f:write(body)
f:close()
tensor = image.load('temp.jpg')
有没有办法将二进制JPG数据火炬张量直接转换而不做写来和读取,从硬盘驱动器?例如:
tensor = CovertBinaryDataToTorchTensor(body)
谢谢!
谢谢。这是正确的答案。 – siavashk