4
4
-- This script demonstrates very basic Lua/Torch stuff.
5
5
6
6
-- To run this script, simply do:
7
- -- torch getstarted.lua
8
- -- and then press 'y' or 'return' at each step, to keep going, or 'n'
9
- -- to terminate.
10
-
11
- require ' gfx.js'
12
-
13
- ---- ------------------------------------------------------------------
14
- -- little function to pause execution, and request user input
15
- function next ()
16
- local answer = nil
17
- while answer ~= ' ' and answer ~= ' y' and answer ~= ' Y' and neverstall ~= true do
18
- io.write (" continue ([y]/n/!)? " )
19
- io.flush ()
20
- answer = io.read ()
21
- if answer == ' !' then
22
- neverstall = true
23
- end
24
- if answer == ' n' then
25
- print (' exiting...' )
26
- os.exit ()
27
- end
28
- end
29
- print ' '
30
- end
7
+ -- th getstarted.lua
8
+ -- To run the script from itorch, in a notebook do:
9
+ -- dofile 'getstarted.lua'
31
10
32
11
---- ------------------------------------------------------------------
33
12
-- snippet 1
@@ -37,24 +16,32 @@ print(a)
37
16
print ' something'
38
17
print (type (a ))
39
18
print (type (' something' ))
40
- next ()
41
19
42
20
---- ------------------------------------------------------------------
43
- -- snippet 3
21
+ -- snippet 2
44
22
require ' image'
45
23
i = image .lena ()
46
- gfx .image (i )
47
- next ()
24
+ if itorch then
25
+ itorch .image (i )
26
+ else
27
+ print (' skipping visualization because the script is not run from itorch' )
28
+ end
48
29
49
30
---- ------------------------------------------------------------------
50
31
-- snippet 4
51
32
require ' nn'
52
33
n = nn .SpatialConvolution (1 ,16 ,12 ,12 )
53
- gfx .image (n .weight , {zoom = 2 , legend = ' ' })
54
- next ()
34
+ if itorch then
35
+ itorch .image (n .weight )
36
+ else
37
+ print (' skipping visualization because the script is not run from itorch' )
38
+ end
55
39
56
40
---- ------------------------------------------------------------------
57
41
-- snippet 5
58
42
res = n :forward (image .rgb2y (i ))
59
- gfx .image (res , {zoom = 0.25 , legend = ' states' })
60
- next ()
43
+ if itorch then
44
+ itorch .image (res )
45
+ else
46
+ print (' skipping visualization because the script is not run from itorch' )
47
+ end
0 commit comments