Skip to content

Instantly share code, notes, and snippets.

@SahilC
Last active March 8, 2017 08:48
Show Gist options
  • Save SahilC/d5e132782bda29342f6d3e692d2dbe8b to your computer and use it in GitHub Desktop.
Save SahilC/d5e132782bda29342f6d3e692d2dbe8b to your computer and use it in GitHub Desktop.
Gist to itorch notebook to help visualize weights for CNN.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 18,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"require 'torch'\n",
"require 'nn'\n",
"require 'nngraph'\n",
"require 'itorch'\n",
"-- exotics\n",
"require 'loadcaffe'\n",
"-- local imports\n",
"local utils = require 'misc.utils'\n",
"require 'misc.DataLoader'\n",
"require 'misc.DataLoaderRaw'\n",
"require 'misc.LanguageModel'\n",
"local net_utils = require 'misc.net_utils'\n",
"require 'cutorch'\n",
"require 'cunn'\n",
"require 'cudnn'"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"nil\t\n"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"checkpoint = torch.load('model_id.t7')\n",
"cnn = checkpoint.protos.cnn\n",
"-- print(cnn.modules[1].weight)"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
" 64\n",
" 3\n",
" 3\n",
" 3\n",
"[torch.LongStorage of size 4]\n",
"\n"
]
},
"execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"weight = cnn.modules[1].weight\n",
"print(weight:size())\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAAMAAAAhCAIAAACTLobVAAABVUlEQVQYlQFKAbX+AWWFix0G8t7ABgMIFybw4t0B8BYD/wcW+u7p9+YFBEkwDeuxGzGGEALq6OwVERDo5vMCCAgLExcPl4ujA+9NFgbF8E1IKwQWHxf//PgD+P0CBf//Pkc56+nvAjyNFAIrEszsKwNACyy+6N0CBxoCAgkF4d3nKSgcA/hdMv74yT0V7gL/BQY1NiXZ1NwEAPv5HiQc7uEFBBfe69S+8sDe2gQeIhoLAREkSTMCCw0M8/j3CQsAA9fq+x4vMAYHAgQ4QDff3enu6/UCGBsR9vLy7OnsAi0QAT5MIebW1gMB/wXq8/U9MSQDA/8K/QUBQj0rBDI4Pv4jAMiizQTq6uvo9/E/DQQECwoGFBQTFQoDAwMRGjz7LeMLwgIYHBjSz9YoJBgEKCge/e332ty4AC0xLiIbJv///wQrLScpISYAAAAC8/X05eXjAAAAyYOEkm5rx7AAAAAASUVORK5CYII=",
"text/plain": [
"Console does not support images"
]
},
"metadata": {
"image/png": {
"height": 33,
"width": 3
}
},
"output_type": "display_data"
}
],
"source": [
"im = image.toDisplayTensor{input=weight}\n",
"\n",
"im = image.scale(im, im:size(1), im:size(2),'bilinear')\n",
"itorch.image(im)\n",
"image.save(\"filters.png\",im)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "iTorch",
"language": "lua",
"name": "itorch"
},
"language_info": {
"name": "lua",
"version": "5.1"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment