Browse Source

'新增队列调度'

master
刘冬煜 4 years ago
parent
commit
1becb21320
44 changed files with 71 additions and 24 deletions
  1. BIN
      style-transform-master/.vs/style-transform-master/v16/.suo
  2. +11
    -0
      style-transform-master/style-transform-master/html/fail.html
  3. +3
    -1
      style-transform-master/style-transform-master/html/generate.html
  4. BIN
      style-transform-master/style-transform-master/obj/Debug/style-transform-master.njsprojAssemblyReference.cache
  5. +1
    -0
      style-transform-master/style-transform-master/public/js/generate.js
  6. BIN
      style-transform-master/style-transform-master/public/uploads/176b2f8f89ba8b530007d6986c2fa9c922a17a4758a.jpg
  7. BIN
      style-transform-master/style-transform-master/public/uploads/176b2fb522f98d18e1c2a7fbb26857de6e644f6d096.jpg
  8. BIN
      style-transform-master/style-transform-master/public/uploads/176b3104418353a1deca2017e116ff55024cf4e0071.jpg
  9. BIN
      style-transform-master/style-transform-master/public/uploads/176b344f40c982f6168b63a0165c869a89be89c8537.jpg
  10. BIN
      style-transform-master/style-transform-master/public/uploads/176b3478124094634bb8c1aceda8d75ea236a21175a.jpg
  11. BIN
      style-transform-master/style-transform-master/public/uploads/176b348fcce3fc160596c09a98cbe47ee2a086c42bd.jpg
  12. BIN
      style-transform-master/style-transform-master/public/uploads/176b34907171b5597171b2e24a6430897b21314cf27.jpg
  13. +0
    -0
      style-transform-master/style-transform-master/public/uploads/24140d7a8f001e552893569e61c45022
  14. +0
    -0
      style-transform-master/style-transform-master/public/uploads/248baa6862e643126e7cc271f5c0db43
  15. +0
    -0
      style-transform-master/style-transform-master/public/uploads/31cb74097c0f137cda202f97fc82c39c
  16. +0
    -0
      style-transform-master/style-transform-master/public/uploads/40bf7fff77f209858c92692c1643db05
  17. +0
    -0
      style-transform-master/style-transform-master/public/uploads/4a528c2b3d548f21efd498d6fcc6ee3e
  18. +0
    -0
      style-transform-master/style-transform-master/public/uploads/6be77319ed4f40cb3764c9d17a0e3e6d
  19. +0
    -0
      style-transform-master/style-transform-master/public/uploads/7b5ee265b28a6127e1655142523c6ce4
  20. +0
    -0
      style-transform-master/style-transform-master/public/uploads/9529e38e01e4ade24d1939ae029ea7ba
  21. +0
    -0
      style-transform-master/style-transform-master/public/uploads/a0e8ff26bdf39d016052c3338fd11ab9
  22. BIN
      style-transform-master/style-transform-master/public/uploads/a66b7d24b2ae85efd87692b33e8e69d1
  23. BIN
      style-transform-master/style-transform-master/public/uploads/b68ae966a5ac0ce4ef5c59feff613a2e
  24. +0
    -0
      style-transform-master/style-transform-master/public/uploads/c0c0d564976eb7c53c1436be2333f31e
  25. BIN
      style-transform-master/style-transform-master/public/uploads/caa0e5cfcb3f4597e4c0ed7790275f31
  26. BIN
      style-transform-master/style-transform-master/public/uploads/ce4073057a801b2ca993fb1469a15e99
  27. BIN
      style-transform-master/style-transform-master/public/uploads/d517817f8cfc575b5a80563ff5359cd3
  28. BIN
      style-transform-master/style-transform-master/public/uploads/d6a0e417d27ad4937da8f0ce7a826fd4
  29. BIN
      style-transform-master/style-transform-master/public/uploads/e634459ff4fd2d759b4691375f922723
  30. +0
    -0
      style-transform-master/style-transform-master/public/uploads/f8abae0975cdc75a23d08fdf7c22b90c
  31. BIN
      style-transform-master/style-transform-master/public/uploads/fe5269e79229d462114741c0ffadf28a
  32. +53
    -23
      style-transform-master/style-transform-master/server.js
  33. +3
    -0
      style-transform-master/style-transform-master/style-transform-master.njsproj

BIN
style-transform-master/.vs/style-transform-master/v16/.suo View File


+ 11
- 0
style-transform-master/style-transform-master/html/fail.html View File

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>Fail</title>
</head>
<body>
<script>alert("服务器繁忙,请稍后重试。");</script>
</body>
</html>

+ 3
- 1
style-transform-master/style-transform-master/html/generate.html View File

@ -34,7 +34,9 @@
<h2><span class="highlight-text">WAITING</span></h2> <h2><span class="highlight-text">WAITING</span></h2>
<p class="col-md-8 col-sm-10 col-xs-12 col-md-offset-2 col-sm-offset-1"> <p class="col-md-8 col-sm-10 col-xs-12 col-md-offset-2 col-sm-offset-1">
正在为您绘画,请稍等……<br />已完成<b><span style="color:darkgoldenrod" id="progress"></span>%</b>
正在为您绘画,请稍等……<br />
您的前方还有<span style="color:darkred" id="wait"></span>个作画任务,请耐心等待。<br />
已完成<b><span style="color:darkgoldenrod" id="progress"></span>%。</b>
</p> </p>
</div> </div>
<div id='prog_out' class="progress-background"> <div id='prog_out' class="progress-background">

BIN
style-transform-master/style-transform-master/obj/Debug/style-transform-master.njsprojAssemblyReference.cache View File


+ 1
- 0
style-transform-master/style-transform-master/public/js/generate.js View File

@ -6,6 +6,7 @@ function getProgress(taskID) {
}).done(function(data) { }).done(function(data) {
$('div[role="progressbar"]').attr("aria-valuenow", data.percentage); $('div[role="progressbar"]').attr("aria-valuenow", data.percentage);
$('div[role="progressbar"]').width(data.percentage + '%'); $('div[role="progressbar"]').width(data.percentage + '%');
$('#wait').html(data.wait);
$('#progress').html(data.percentage); $('#progress').html(data.percentage);
if(data.status == 1) { if(data.status == 1) {
window.location.replace('./success?taskID='+taskID); window.location.replace('./success?taskID='+taskID);

BIN
style-transform-master/style-transform-master/public/uploads/176b2f8f89ba8b530007d6986c2fa9c922a17a4758a.jpg View File

Before After
Width: 512  |  Height: 384  |  Size: 45 KiB

BIN
style-transform-master/style-transform-master/public/uploads/176b2fb522f98d18e1c2a7fbb26857de6e644f6d096.jpg View File

Before After
Width: 512  |  Height: 384  |  Size: 62 KiB

BIN
style-transform-master/style-transform-master/public/uploads/176b3104418353a1deca2017e116ff55024cf4e0071.jpg View File

Before After
Width: 512  |  Height: 384  |  Size: 62 KiB

BIN
style-transform-master/style-transform-master/public/uploads/176b344f40c982f6168b63a0165c869a89be89c8537.jpg View File

Before After
Width: 512  |  Height: 384  |  Size: 45 KiB

BIN
style-transform-master/style-transform-master/public/uploads/176b3478124094634bb8c1aceda8d75ea236a21175a.jpg View File

Before After
Width: 512  |  Height: 384  |  Size: 60 KiB

BIN
style-transform-master/style-transform-master/public/uploads/176b348fcce3fc160596c09a98cbe47ee2a086c42bd.jpg View File

Before After
Width: 512  |  Height: 384  |  Size: 60 KiB

BIN
style-transform-master/style-transform-master/public/uploads/176b34907171b5597171b2e24a6430897b21314cf27.jpg View File

Before After
Width: 512  |  Height: 384  |  Size: 45 KiB

style-transform-master/style-transform-master/public/uploads/1c9986aaecb7d17aaddbeaaeb006e37f → style-transform-master/style-transform-master/public/uploads/24140d7a8f001e552893569e61c45022 View File


style-transform-master/style-transform-master/public/uploads/332d42af8f74e985fb1571620b4a860b → style-transform-master/style-transform-master/public/uploads/248baa6862e643126e7cc271f5c0db43 View File


style-transform-master/style-transform-master/public/uploads/4b1e4e9c4e4fbe9de78602e683b21ba6 → style-transform-master/style-transform-master/public/uploads/31cb74097c0f137cda202f97fc82c39c View File


style-transform-master/style-transform-master/public/uploads/34c21eb4ab6d5f21fe38e0e7c5e0bc51 → style-transform-master/style-transform-master/public/uploads/40bf7fff77f209858c92692c1643db05 View File


style-transform-master/style-transform-master/public/uploads/cc3197b0d46fdb5831763b680c3ace57 → style-transform-master/style-transform-master/public/uploads/4a528c2b3d548f21efd498d6fcc6ee3e View File


style-transform-master/style-transform-master/public/uploads/266574aed51b4b86b16df83ce27ef93d → style-transform-master/style-transform-master/public/uploads/6be77319ed4f40cb3764c9d17a0e3e6d View File


style-transform-master/style-transform-master/public/uploads/cdd8721916bc1b41e4de3a3c406953cd → style-transform-master/style-transform-master/public/uploads/7b5ee265b28a6127e1655142523c6ce4 View File


style-transform-master/style-transform-master/public/uploads/f08b08ca187fecef6f70582cc988d459 → style-transform-master/style-transform-master/public/uploads/9529e38e01e4ade24d1939ae029ea7ba View File


style-transform-master/style-transform-master/public/uploads/32a9eb5edee2387c3e20c301679db380 → style-transform-master/style-transform-master/public/uploads/a0e8ff26bdf39d016052c3338fd11ab9 View File


BIN
style-transform-master/style-transform-master/public/uploads/a66b7d24b2ae85efd87692b33e8e69d1 View File

Before After
Width: 300  |  Height: 312  |  Size: 23 KiB

BIN
style-transform-master/style-transform-master/public/uploads/b68ae966a5ac0ce4ef5c59feff613a2e View File

Before After
Width: 300  |  Height: 312  |  Size: 23 KiB

style-transform-master/style-transform-master/public/uploads/d69579c100d6143a74359598b5277cc9 → style-transform-master/style-transform-master/public/uploads/c0c0d564976eb7c53c1436be2333f31e View File


BIN
style-transform-master/style-transform-master/public/uploads/caa0e5cfcb3f4597e4c0ed7790275f31 View File

Before After
Width: 680  |  Height: 510  |  Size: 93 KiB

BIN
style-transform-master/style-transform-master/public/uploads/ce4073057a801b2ca993fb1469a15e99 View File

Before After
Width: 680  |  Height: 510  |  Size: 93 KiB

BIN
style-transform-master/style-transform-master/public/uploads/d517817f8cfc575b5a80563ff5359cd3 View File

Before After
Width: 739  |  Height: 462  |  Size: 206 KiB

BIN
style-transform-master/style-transform-master/public/uploads/d6a0e417d27ad4937da8f0ce7a826fd4 View File

Before After
Width: 680  |  Height: 510  |  Size: 93 KiB

BIN
style-transform-master/style-transform-master/public/uploads/e634459ff4fd2d759b4691375f922723 View File

Before After
Width: 300  |  Height: 312  |  Size: 23 KiB

style-transform-master/style-transform-master/public/uploads/876ae07ab5531800fbcabcdca5e507a2 → style-transform-master/style-transform-master/public/uploads/f8abae0975cdc75a23d08fdf7c22b90c View File


BIN
style-transform-master/style-transform-master/public/uploads/fe5269e79229d462114741c0ffadf28a View File

Before After
Width: 300  |  Height: 312  |  Size: 23 KiB

+ 53
- 23
style-transform-master/style-transform-master/server.js View File

@ -28,26 +28,19 @@ var upload = multer({ dest: 'public/uploads/' });
var progress = {}; var progress = {};
var relationfile = {}; var relationfile = {};
server.post('/generate', upload.fields([{ name: 'content_image', maxCount: 1 }, { name: 'style_image', maxCount: 1 }]), function (req, res) {
let max_epoch = req.body.max_epoch;
let md5 = crypto.createHash('md5');
console.log(req.files);
console.log("Epoch = " + max_epoch);
if (!req.files.content_image || !req.files.style_image) {
progress[taskID] = {percentage: 0, max_epoch: 0, status: -2};
}
var isIdle = true;
var queue = [];
var totalTask = 0;
let taskID = Date.now().toString(16) + md5.update(req.files.content_image[0].filename + req.files.style_image[0].filename).digest('hex');
function run_child(taskID) {
let child = exec(`python run_main.py --content ./public/uploads/${relationfile[taskID].content} --style ./public/uploads/${relationfile[taskID].style} --output ./public/uploads/${taskID}.jpg --num_iter ${progress[taskID].max_epoch}`);
console.log(taskID + " start!"); console.log(taskID + " start!");
console.log(`content: ${relationfile[taskID].content}`);
console.log(`style: ${relationfile[taskID].style}`)
console.log(`output: ${taskID}.jpg`);
console.log(`num_iter = ${progress[taskID].max_epoch}`);
relationfile[taskID] = {content: req.files.content_image[0].filename, style: req.files.style_image[0].filename};
let child = exec(`python run_main.py --content ./public/uploads/${req.files.content_image[0].filename} --style ./public/uploads/${req.files.style_image[0].filename} --output ./public/uploads/${taskID}.jpg --num_iter ${max_epoch}`);
//console.log(`python run_main.py --content ./uploads/${req.files.content_image[0].filename} --style ./uploads/${req.files.style_image[0].filename} --output ./uploads/${taskID}.jpg --num_iter ${max_epoch}`);
progress[taskID] = {percentage: 0, max_epoch: parseInt(max_epoch), status: 0};
child.stdout.on("data", function (data) { child.stdout.on("data", function (data) {
let args = data.split(' '); let args = data.split(' ');
let signal = args[0]; let signal = args[0];
@ -69,8 +62,6 @@ server.post('/generate', upload.fields([{ name: 'content_image', maxCount: 1 },
progress[taskID].totalLoss = totalLoss; progress[taskID].totalLoss = totalLoss;
progress[taskID].ContentLoss = ContentLoss; progress[taskID].ContentLoss = ContentLoss;
progress[taskID].StyleLoss = StyleLoss; progress[taskID].StyleLoss = StyleLoss;
//console.log(taskID + ": " + args);
}); });
child.on("close", (code) => { child.on("close", (code) => {
@ -80,11 +71,45 @@ server.post('/generate', upload.fields([{ name: 'content_image', maxCount: 1 },
progress[taskID].status = -1; progress[taskID].status = -1;
} }
console.log(taskID + " done!"); console.log(taskID + " done!");
totalTask += 1;
if (queue.length == 0) {
isIdle = true;
} else {
let nextTaskID = queue.shift();
run_child(nextTaskID);
}
}); });
}
server.post('/generate', upload.fields([{ name: 'content_image', maxCount: 1 }, { name: 'style_image', maxCount: 1 }]), function (req, res) {
let max_epoch = req.body.max_epoch;
let md5 = crypto.createHash('md5');
console.log(req.files);
console.log("Epoch = " + max_epoch);
if (!req.files.content_image || !req.files.style_image) {
progress[taskID] = {percentage: 0, max_epoch: 0, status: -2};
}
let taskID = Date.now().toString(16) + md5.update(req.files.content_image[0].filename + req.files.style_image[0].filename).digest('hex');
relationfile[taskID] = {content: req.files.content_image[0].filename, style: req.files.style_image[0].filename};
progress[taskID] = {percentage: 0, max_epoch: parseInt(max_epoch), status: 0, wait: totalTask + queue.length + 1};
if (isIdle) {
isIdle = false;
progress[taskID].wait -= 1;
run_child(taskID);
} else {
queue.push(taskID);
}
let $ = cheerio.load(fs.readFileSync("./html/generate.html")); let $ = cheerio.load(fs.readFileSync("./html/generate.html"));
$('script[name="go"]').html(`setInterval(function() {getProgress("${taskID}");}, 1000);`);
$('script[name="go"]').html(`getProgress("${taskID}"); setInterval(function() {getProgress("${taskID}");}, 1000);`);
res.writeHead(200, { 'Content-type': 'text/html' }); res.writeHead(200, { 'Content-type': 'text/html' });
res.end($.html()); res.end($.html());
@ -108,12 +133,17 @@ server.get('/success', function (req, res) {
}); });
server.get('/fail', function (req, res) { server.get('/fail', function (req, res) {
res.writeHead(200, { 'Content-type': 'text/html' });
res.end(fs.readFileSync("./html/fail.html"));
}); });
server.get('/progress', function (req, res) { server.get('/progress', function (req, res) {
if(req.query.taskID) {
res.json(progress[req.query.taskID]);
if(req.query.taskID && progress[req.query.taskID]) {
let result_obj = {};
result_obj.percentage = progress[req.query.taskID].percentage;
result_obj.wait = progress[req.query.taskID].wait - totalTask;
result_obj.status = progress[req.query.taskID].status;
res.json(result_obj);
} }
}); });

+ 3
- 0
style-transform-master/style-transform-master/style-transform-master.njsproj View File

@ -28,6 +28,9 @@
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Content Include="html\fail.html">
<SubType>Code</SubType>
</Content>
<Content Include="html\generate.html" /> <Content Include="html\generate.html" />
<Content Include="html\index.html" /> <Content Include="html\index.html" />
<Content Include="html\success.html"> <Content Include="html\success.html">

Loading…
Cancel
Save