import torch
import torchvision.models as models
model = models.densenet121(pretrained=True)
x = torch.randn((1, 3, 224, 224), requires_grad=True)
with torch.autograd.profiler.profile(use_cuda=True) as prof:
model(x)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from torch.autograd import Variable | |
import torch | |
from torch import nn | |
from collections import OrderedDict | |
from IPython import embed | |
from torch.autograd.function import InplaceFunction, Function | |
import torch.nn.functional as F | |
import math | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% parameters | |
delta = 0.5; | |
a2 = 0.1; | |
a1 = 100; | |
number_of_pieces = 100; % number of pieces we want to divide | |
%% | |
b2 = delta/tanh(a2*delta); | |
b1 = delta/tanh(a1*delta); | |
thres_min = zeros(1,number_of_pieces)+1000; | |
amin = zeros(1,number_of_pieces); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\usepackage{soul} | |
\newcommand{\xinc}[1]{\textcolor{blue}{[Xin:$\rightarrow$#1]}} | |
\newcommand{\xina}[1]{\textcolor{blue}{[Xin:$+$#1]}} | |
\newcommand{\xin}[1]{\textcolor{blue}{[Xin:#1]}} | |
\newcommand{\xind}[1]{\textcolor{blue}{[Xin:\st{#1}]}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://repl.it/ | |
# coding:utf-8 | |
from turtle import * | |
def nose(x,y):#鼻子 | |
pu() | |
goto(x,y) | |
pd() | |
seth(-30) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch.nn as nn | |
import torch.nn.functional as F | |
import torch | |
class DeepInversionFeatureHook(): | |
''' | |
Implementation of the forward hook to track feature statistics and compute a loss on them. | |
Will compute mean and variance, and will use l2 as a loss | |
''' | |
def __init__(self, module): | |
self.hook = module.register_forward_hook(self.hook_fn) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from graphviz import Digraph | |
from torch.autograd import Variable | |
import torch | |
def make_dot(var, params=None): | |
if params is not None: | |
assert isinstance(params.values()[0], Variable) | |
param_map = {id(v): k for k, v in params.items()} |