-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path8.py
executable file
·73 lines (55 loc) · 1.84 KB
/
8.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/env python
import time
from module import *
from typing import List
import torch
import torch.nn as nn
import torch.nn.functional as F
from torchvision.datasets import MNIST
from torch.utils.data import DataLoader
from torchvision import transforms as tfs
import torchopt
import functorch
import aot
device = torch.device("cpu")
class MyTransform:
def __init__(self):
pass
def __call__(self, img):
img = tfs.functional.rotate(img, -90)
img = tfs.functional.hflip(img)
img = img.map_(img, lambda a, b: 1.0 - a)
return img
trainset = MNIST(root = "",
#split = "digits",
train = True,
download = True,
transform = tfs.Compose([tfs.PILToTensor(),
tfs.Resize(29),
tfs.ConvertImageDtype(torch.float32),
MyTransform()
]))
testset = MNIST(root = "",
#split = "digits",
train = False,
download = True,
transform = tfs.Compose([tfs.PILToTensor(),
tfs.Resize(29),
tfs.ConvertImageDtype(torch.float32),
MyTransform()
]))
trainset_size = len(trainset)
testset_size = len(testset)
batch_size = 16
trainset_dataloader = DataLoader(trainset, batch_size = 16, shuffle = False);
testset_dataloader = DataLoader(testset, batch_size = 16, shuffle = False);
my_module = MyModule()
random_input = torch.randn([batch_size, 1, 29, 29])
random_target = torch.randn([16, 10], requires_grad = False)
preds = my_module(random_input)
loss_fn = nn.CrossEntropyLoss()
loss_fn.to(device)
import my_graph_capture
ts_mod, states = my_graph_capture.capture_TorchScript(my_module, 0, random_input)
print(ts_mod)
print(states)