Skip to content

Commit d72d1ef

Browse files
committed
modified
1 parent 66da313 commit d72d1ef

21 files changed

+11219
-11034
lines changed

index.html

Lines changed: 68 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<html>
2-
2+
<title>neural style board</title>
33
<head>
44
<!-- <script src="https://code.highcharts.com/highcharts.js"></script> -->
55

@@ -17,28 +17,85 @@
1717
<script src="/static/stock/highstock.js"></script>
1818
<script src="/static/stock/modules/exporting.js"></script>
1919
<script src="/static/stock/themes/dark-unica-nofont.js"></script>
20+
<link rel="stylesheet" type="text/css" href="//cdn.bootcss.com/materialize/0.97.6/css/materialize.min.css"/>
21+
<script src="//cdn.bootcss.com/materialize/0.97.6/js/materialize.min.js"></script>
2022

2123
<!-- Additional files for the Highslide popup effect -->
2224
<script src="/static/highslide/highslide-full.min.js"></script>
2325
<script src="/static/highslide.config.js" charset="utf-8"></script>
2426
<link rel="stylesheet" type="text/css" href="/static/highslide/highslide.css"/>
2527
<script src="/static/board.js" charset="utf-8"></script>
28+
2629
</head>
2730

2831
<script>
29-
loadjson('/result512x512+very-high-learning-rate.json');
30-
</script>
32+
// loadjson('{{static_url("result.json")}}' );
33+
$.getJSON('/init', function (json) {
34+
loadjson(json);
35+
})
36+
37+
var trained = false;
38+
function train() {
39+
$.ajax('/train')
40+
if (trained){
41+
console.log('pause');
42+
$('#train').get(0).innerHTML = 'train';
43+
$('#status').get(0).innerHTML = 'pause';
44+
trained = false;
45+
}
3146

32-
<div id="container" style="height: 90%; width: 100%; min-width: 310px"></div>
47+
else {
48+
console.log('train');
49+
$('#train').get(0).innerHTML = 'pause';
50+
$('#status').get(0).innerHTML = 'training';
51+
trained = true;
52+
}
53+
}
3354

34-
<div style="height: 10%;">
35-
<button onclick="toDefault()" style="height: 50%; margin: 5px;"> Default View </button>
36-
<button onclick="toValue()" style="height: 50%; margin: 5px;"> Value compare view </button>
37-
<button onclick="toPercent()" style="height: 50%; margin: 5px;"> Percent compare view </button>
38-
<button onclick="toLogarithmic()" style="height: 50%; margin: 5px;"> Logarithmic View </button>
55+
function stop() {
56+
$.ajax('/stop')
57+
$('#train').get(0).innerHTML = 'train';
58+
$('#status').get(0).innerHTML = 'stop';
59+
}
3960

40-
</div>
61+
$(document).ready(function() {
62+
$('select').material_select();
63+
$('#lr').on('change', function(e) {
64+
$.post('http://localhost:8000/lr?lr='+this.value);
65+
});
66+
updater.poll();
67+
});
68+
69+
70+
71+
</script>
72+
<!--<span id="test" style="padding-left: 240px;"></span>-->
73+
<ul class="side-nav fixed">
74+
<li style="text-align: center"><b >status: <span id="status">stop</span></b></li>
75+
<li><a class="waves-effect waves-light btn cyan accent-4 white-text" href="javascript: train()" id="train">train</a></li>
76+
<li><a class="waves-effect waves-light btn cyan accent-4 white-text" href="javascript: stop()" id="stop">stop</a></li>
77+
<li><a class="waves-effect waves-light btn cyan accent-4 white-text" href="javascript: toDefault()">Default View</a></li>
78+
<li><a class="waves-effect waves-light btn cyan accent-4 white-text" href="javascript: toValue()">Value compare View</a></li>
79+
<li><a class="waves-effect waves-light btn cyan accent-4 white-text" href="javascript: toPercent()">Percent compare View</a></li>
80+
<!--<li><a class="waves-effect waves-light btn cyan accent-4 white-text" href="javascript: toLogarithmic()">Logarithmic View</a></li>-->
81+
<!--<li style="height: 100px;">-->
82+
<div class="container">
83+
<div class="row">
84+
<div class="input-field col s12">
85+
<select id="lr">
86+
<option value="1.0">1.0</option>
87+
<option value="0.3">0.3</option>
88+
<option value="0.1">0.1</option>
89+
<option value="0.1">0.03</option>
90+
<option value="0.1">0.01</option>
91+
</select>
92+
<label>learning rate</label>
93+
</div>
94+
</div>
4195

42-
<br>
96+
</div>
4397

98+
<!--</li>-->
99+
</ul>
100+
<div id="container" style="height: 100%; width: 100%; min-width: 310px; padding-left: 240px;"></div>
44101
</html>

lbfgs.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
# local x, losses = optim.lbfgs(feval, img, {})
1+
# TODO: implement the l-bfgs algorithm
2+
# local x, losses = optim.lbfgs(feval, img, {})
3+

main.py

Lines changed: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,54 @@
99
from training_record import TrainingRecorder
1010
from img_prep import img_in, img_save, preprocess_image, grey_image
1111
from settings import content_path, style_path, loss_set, result_dir
12+
import requests, time
1213

13-
# load content and style image
14-
content, style = img_in(content_path, style_path)
15-
16-
tr = TrainingRecorder(loss_set, result_dir, img_save, '.png')
17-
18-
idx = tr.get_head() - 1
19-
if idx >= 0:
20-
x = preprocess_image(tr.get_name(idx))
21-
else:
22-
x = grey_image()
23-
24-
idx += 1
2514

26-
model = Model(content, style, x)
27-
28-
try:
29-
for i in range(idx, 10000):
30-
print('Start of iteration', i)
31-
loss, result = model.update()
32-
# save current generated image
33-
tr.record(i, loss, result)
34-
35-
except KeyboardInterrupt:
36-
tr.export_file()
15+
# load content and style image
16+
def start_training():
17+
18+
content, style = img_in(content_path, style_path)
19+
20+
tr = TrainingRecorder(loss_set, result_dir, img_save, '.png')
21+
22+
idx = tr.get_head() - 1
23+
if idx >= 0:
24+
x = preprocess_image(tr.get_name(idx))
25+
else:
26+
x = grey_image()
27+
28+
idx += 1
29+
30+
model = Model(content, style, x)
31+
32+
33+
lst_lr = 1.0
34+
try:
35+
for i in range(idx, 10000):
36+
status = requests.get('http://localhost:8000/status').text
37+
lr = float(requests.get('http://localhost:8000/lr').text)
38+
if status == 'pause':
39+
i -= 1
40+
while True:
41+
time.sleep(1)
42+
status = requests.get('http://localhost:8000/status').text
43+
if status != 'pause':
44+
break
45+
elif status == 'training':
46+
print('Start of iteration', i)
47+
# msg = 'Start of iteration ' + str(i)
48+
if lst_lr != lr:
49+
# if learning rate has changes, set a new lr for the optimizer
50+
model.set_lr(lr)
51+
loss, result = model.update()
52+
# save current generated image
53+
tr.record(i, loss, result)
54+
lst_lr = lr
55+
elif status == 'stop':
56+
print('stop training and save weights into json file.')
57+
# msg = 'stop training and save weights into json file.'
58+
tr.export_file()
59+
break
60+
61+
except KeyboardInterrupt:
62+
tr.export_file()

0 commit comments

Comments
 (0)