Chris Parry
Chris Parry

Reputation: 3057

Visualizing CNN weights from Torch Tensor

I have a Torch Cuda Tensor of size 64x64x3x3 and I want to visualise its weights for a given layer as follows:

local layer = model:get(3)
local weights = layer.weight
local imgDisplay = image.toDisplayTensor{input=weights, padding=2, scaleeach=80}

This is producing an error:

'packed must be a HxW or KxHxW or Kx3xHxW tensor, or a list of tensors

How should I resize the tensor in order to use toDisplayTensor? Thanks.

Upvotes: 1

Views: 594

Answers (1)

lejlot
lejlot

Reputation: 66805

Error seems to be very straight forward - you should provide data in the form of either:

  • HxW - height x weight, 2-dim tensor, one per kernel/channel pair
  • KxHxW - kernels x height x weight, 3-dim tensor, one per channel (for example if data is grayscale)
  • Kx3xHxW - kernels x channels x height x weight, 4-dim tensor, one per network layer (for 3-channel colour data, as the second dim will be mapped to RGB scale)

In your case I assume that your image is 64x64 (or after current convolution is)? Then you need 3x3x64x64 Tensor, where first dimension is the one iterating over kernels, second - over colors, third and forth over the image itself.

Upvotes: 1

Related Questions