Visualizing CNN weights, load, save ‘.t7 & log as “.html” file from Torch Tensor

 

==================================================

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}

 

ref: http://stackoverflow.com/questions/35192022/visualizing-cnn-weights-from-torch-tensor

==========================================================================

To load .t7 file 

trainData = torch.load(train.t7)

testData = torch.load(test.t7)

To save .t7 file

torch.save(train.t7,trainData)

torch.save(test.t7,testData)

 

Ref : https://github.com/torch/demos/blob/master/person-detector/data.lua

To view log as .html file  and other log as well

REf code: https://github.com/szagoruyko/cifar.torch/blob/master/train.lua

function test()
— disable flips, dropouts and batch normalization
model:evaluate()
print(c.blue ‘==>’..” testing”)
local bs = 125
for i=1,provider.testData.data:size(1),bs do
local outputs = model:forward(provider.testData.data:narrow(1,i,bs))
confusion:batchAdd(outputs, provider.testData.labels:narrow(1,i,bs))
end

confusion:updateValids()
print(‘Test accuracy:’, confusion.totalValid * 100)

if testLogger then
paths.mkdir(opt.save)
testLogger:add{train_acc, confusion.totalValid * 100}
testLogger:style{‘-‘,’-‘}
testLogger:plot()

if paths.filep(opt.save..’/test.log.eps’) then
local base64im
do
os.execute((‘convert -density 200 %s/test.log.eps %s/test.png’):format(opt.save,opt.save))
os.execute((‘openssl base64 -in %s/test.png -out %s/test.base64′):format(opt.save,opt.save))
local f = io.open(opt.save..’/test.base64′)
if f then base64im = f:read’*all’ end
end

local file = io.open(opt.save..’/report.html’,’w’)
file:write(([[
<!DOCTYPE html>
<html>
<body>
<title>%s – %s</title>
<img src=”data:image/png;base64,%s”>
<h4>optimState:</h4>
<table>
]]):format(opt.save,epoch,base64im))
for k,v in pairs(optimState) do
if torch.type(v) == ‘number’ then
file:write(‘<tr><td>’..k..'</td><td>’..v..'</td></tr>\n’)
end
end
file:write'</table><pre>\n’
file:write(tostring(confusion)..’\n’)
file:write(tostring(model)..’\n’)
file:write'</pre></body></html>’
file:close()
end
end

— save model every 50 epochs
if epoch % 50 == 0 then
local filename = paths.concat(opt.save, ‘model.net’)
print(‘==> saving model to ‘..filename)
torch.save(filename, model:get(3):clearState())
end

confusion:zero()
end

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s