-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexamples.jl
42 lines (40 loc) · 852 Bytes
/
examples.jl
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
using Flux
# set up data
# incomplete example pipeline with arbitrary cutoff points
...
X = imgs
Y = onehotbatch(labels, 0:4)
...
if checkmem() < 0.2
@error("Memory free is less than 20%")
callout("Stopping. Memory problem")
#break
end
...
m = Chain(...)
function loss(...)
...
end
dataset = Flux.Data.DataLoader(X, Y, batchsize=32, shuffle=true)
...
# callback function
evalcb = () ->
begin
@show(loss(X, Y)),
if loss(X,Y) < 0.75
callout("early stop")
Flux.stop()
end
# cpu temperature
cput = checkcpu()
# in this example temperature of 70 C is the cutoff
while cput > 70
@warn("watching CPU... ($cput)")
callout("CPU is hot")
# rest the CPU for 60 seconds
sleep(60)
cput = checkcpu()
end
end # callback
Flux.@epochs 7 Flux.train!(loss, params(m), dataset, opt, cb = throttle(evalcb,1))
callout("Training done")