Skip to content

Commit

Permalink
Default Tensor type fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ili3p committed Sep 27, 2016
1 parent c651e0a commit 4f74b38
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ function M.configure(config)
end

function M.image(img, opts)

local defaultType = torch.getdefaulttensortype()
-- the image package expects this to be DoubleTensor
-- if CudaTensor then clampImage from package image will attempt to index field 'image' (a nil value) of the CudaTensor
torch.setdefaulttensortype('torch.DoubleTensor')

-- options:
opts = opts or {}

Expand All @@ -82,6 +88,7 @@ function M.image(img, opts)
local inmem_img = image.compressJPG(img)
local imgdata = 'data:image/jpg;base64,' .. mime.b64(ffi.string(inmem_img:data(), inmem_img:nElement()))

torch.setdefaulttensortype(defaultType)

return pane('image', opts.win, opts.title, { src=imgdata, labels=opts._labels, width=opts.width })
end
Expand Down

0 comments on commit 4f74b38

Please sign in to comment.