Update.
[pytorch.git] / sizer.py
1 #!/usr/bin/env python
2
3 # Any copyright is dedicated to the Public Domain.
4 # https://creativecommons.org/publicdomain/zero/1.0/
5
6 # Written by Francois Fleuret <francois@fleuret.org>
7
8 import os, stat, sys
9 import time
10 import torch
11 from torch import nn
12
13 ######################################################################
14
15 if len(sys.argv) < 2:
16     print(sys.argv[0] + ''' <file to monitor>
17
18 For example:
19
20 (17, 3, 60, 80)
21 nn.Conv2d(3, 32, 3, padding = 1)
22 nn.MaxPool2d(2)
23 nn.Conv2d(32, 32, 3, padding = 1)
24 nn.MaxPool2d(2)
25 nn.Conv2d(32, 64, 3, padding = 1)
26 nn.MaxPool2d(5)
27 nn.Conv2d(64, 64, (3, 4))''')
28     exit(1)
29
30 ######################################################################
31
32 t = 0
33
34 while True:
35     pt = t
36     t = os.stat(sys.argv[1])[stat.ST_MTIME]
37     if t > pt:
38         pt = t
39         os.system('clear')
40         try:
41             temp = [l.strip('\n\r') for l in open(sys.argv[1], 'r').readlines()]
42             x = torch.zeros(eval(temp.pop(0)))
43             print('-> ' + str(tuple(x.size())))
44             for k in temp:
45                 print('   ' + k)
46                 x = eval(k + '(x)')
47                 print('-> ' + str(tuple(x.size())))
48         except:
49             print('** Error **')
50     time.sleep(1)