Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

Commit

Permalink
added references
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinzakka committed Feb 20, 2018
1 parent c767657 commit 23cabac
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 267 deletions.
211 changes: 10 additions & 201 deletions Playground.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 43,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -176,218 +176,27 @@
},
{
"cell_type": "code",
"execution_count": 138,
"execution_count": 79,
"metadata": {},
"outputs": [],
"source": [
"conv_net = Net()"
]
},
{
"cell_type": "code",
"execution_count": 139,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Variable containing:\n",
"(0 ,.,.) = \n",
" -0.0385 0.1033 0.0002 0.1075 -0.1455\n",
" 0.0613 0.0409 -0.0703 -0.0915 -0.0821\n",
" 0.0756 0.1122 -0.1820 -0.1431 0.0584\n",
" 0.1220 0.1551 -0.0539 0.1442 0.1441\n",
" 0.0291 -0.1069 0.1430 -0.0193 0.1652\n",
"[torch.FloatTensor of size 1x5x5]"
]
},
"execution_count": 139,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"W = list(conv_net.parameters())[0].clone()\n",
"W[1]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 144,
"metadata": {},
"outputs": [],
"source": [
"dtype = torch.FloatTensor"
]
},
{
"cell_type": "code",
"execution_count": 150,
"metadata": {},
"outputs": [],
"source": [
"reg_loss = Variable(torch.zeros(1), requires_grad=True).type(dtype)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 140,
"metadata": {},
"outputs": [],
"source": [
"max_norm(conv_net, 0.01, eps=1e-8)"
]
},
{
"cell_type": "code",
"execution_count": 141,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Variable containing:\n",
"(0 ,.,.) = \n",
" -0.0385 0.1033 0.0002 0.1075 -0.1455\n",
" 0.0613 0.0409 -0.0703 -0.0915 -0.0821\n",
" 0.0756 0.1122 -0.1820 -0.1431 0.0584\n",
" 0.1220 0.1551 -0.0539 0.1442 0.1441\n",
" 0.0291 -0.1069 0.1430 -0.0193 0.1652\n",
"[torch.FloatTensor of size 1x5x5]"
]
},
"execution_count": 141,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"W = list(conv_net.parameters())[0].clone()\n",
"W[1]"
"model = Net()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"W = torch.randn(100, 100)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"norm = W.norm(2)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"my = torch.sum(torch.pow(W, 2))"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"10089.580074277259"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"my"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"10089.580071259983"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"norm ** 2"
"orth_loss = Variable(torch.FloatTensor(1), requires_grad=True)\n",
"for name, param in model.named_parameters():\n",
" if 'bias' not in name:\n",
" W_reshaped = W.view(W.shape[0], -1)\n",
" sym = torch.mm(W_reshaped, torch.t(W_reshaped))\n",
" sym -= Variable(torch.eye(W_reshaped.shape[0]))\n",
" orth_loss = orth_loss + sym.sum()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
Loading

0 comments on commit 23cabac

Please sign in to comment.