diff --git a/style-transform-master/.vs/style-transform-master/v16/.suo b/style-transform-master/.vs/style-transform-master/v16/.suo index 05d30f9..b607672 100644 Binary files a/style-transform-master/.vs/style-transform-master/v16/.suo and b/style-transform-master/.vs/style-transform-master/v16/.suo differ diff --git a/style-transform-master/style-transform-master/html/fail.html b/style-transform-master/style-transform-master/html/fail.html new file mode 100644 index 0000000..0de3692 --- /dev/null +++ b/style-transform-master/style-transform-master/html/fail.html @@ -0,0 +1,11 @@ + + + + + + Fail + + + + + \ No newline at end of file diff --git a/style-transform-master/style-transform-master/html/generate.html b/style-transform-master/style-transform-master/html/generate.html index 576dd63..dfc1624 100644 --- a/style-transform-master/style-transform-master/html/generate.html +++ b/style-transform-master/style-transform-master/html/generate.html @@ -34,7 +34,9 @@

WAITING

- 正在为您绘画,请稍等……
已完成% + 正在为您绘画,请稍等……
+ 您的前方还有个作画任务,请耐心等待。
+ 已完成%。

diff --git a/style-transform-master/style-transform-master/obj/Debug/style-transform-master.njsprojAssemblyReference.cache b/style-transform-master/style-transform-master/obj/Debug/style-transform-master.njsprojAssemblyReference.cache index a3ab5aa..80efde4 100644 Binary files a/style-transform-master/style-transform-master/obj/Debug/style-transform-master.njsprojAssemblyReference.cache and b/style-transform-master/style-transform-master/obj/Debug/style-transform-master.njsprojAssemblyReference.cache differ diff --git a/style-transform-master/style-transform-master/public/js/generate.js b/style-transform-master/style-transform-master/public/js/generate.js index 9964757..7b3a4f4 100644 --- a/style-transform-master/style-transform-master/public/js/generate.js +++ b/style-transform-master/style-transform-master/public/js/generate.js @@ -6,6 +6,7 @@ function getProgress(taskID) { }).done(function(data) { $('div[role="progressbar"]').attr("aria-valuenow", data.percentage); $('div[role="progressbar"]').width(data.percentage + '%'); + $('#wait').html(data.wait); $('#progress').html(data.percentage); if(data.status == 1) { window.location.replace('./success?taskID='+taskID); diff --git a/style-transform-master/style-transform-master/public/uploads/176b2f8f89ba8b530007d6986c2fa9c922a17a4758a.jpg b/style-transform-master/style-transform-master/public/uploads/176b2f8f89ba8b530007d6986c2fa9c922a17a4758a.jpg deleted file mode 100644 index 9ab5817..0000000 Binary files a/style-transform-master/style-transform-master/public/uploads/176b2f8f89ba8b530007d6986c2fa9c922a17a4758a.jpg and /dev/null differ diff --git a/style-transform-master/style-transform-master/public/uploads/176b2fb522f98d18e1c2a7fbb26857de6e644f6d096.jpg b/style-transform-master/style-transform-master/public/uploads/176b2fb522f98d18e1c2a7fbb26857de6e644f6d096.jpg deleted file mode 100644 index 65c1a99..0000000 Binary files a/style-transform-master/style-transform-master/public/uploads/176b2fb522f98d18e1c2a7fbb26857de6e644f6d096.jpg and /dev/null differ diff --git a/style-transform-master/style-transform-master/public/uploads/176b3104418353a1deca2017e116ff55024cf4e0071.jpg b/style-transform-master/style-transform-master/public/uploads/176b3104418353a1deca2017e116ff55024cf4e0071.jpg deleted file mode 100644 index 65c1a99..0000000 Binary files a/style-transform-master/style-transform-master/public/uploads/176b3104418353a1deca2017e116ff55024cf4e0071.jpg and /dev/null differ diff --git a/style-transform-master/style-transform-master/public/uploads/176b344f40c982f6168b63a0165c869a89be89c8537.jpg b/style-transform-master/style-transform-master/public/uploads/176b344f40c982f6168b63a0165c869a89be89c8537.jpg new file mode 100644 index 0000000..542bab2 Binary files /dev/null and b/style-transform-master/style-transform-master/public/uploads/176b344f40c982f6168b63a0165c869a89be89c8537.jpg differ diff --git a/style-transform-master/style-transform-master/public/uploads/176b3478124094634bb8c1aceda8d75ea236a21175a.jpg b/style-transform-master/style-transform-master/public/uploads/176b3478124094634bb8c1aceda8d75ea236a21175a.jpg new file mode 100644 index 0000000..6b9e816 Binary files /dev/null and b/style-transform-master/style-transform-master/public/uploads/176b3478124094634bb8c1aceda8d75ea236a21175a.jpg differ diff --git a/style-transform-master/style-transform-master/public/uploads/176b348fcce3fc160596c09a98cbe47ee2a086c42bd.jpg b/style-transform-master/style-transform-master/public/uploads/176b348fcce3fc160596c09a98cbe47ee2a086c42bd.jpg new file mode 100644 index 0000000..ec2b2c1 Binary files /dev/null and b/style-transform-master/style-transform-master/public/uploads/176b348fcce3fc160596c09a98cbe47ee2a086c42bd.jpg differ diff --git a/style-transform-master/style-transform-master/public/uploads/176b34907171b5597171b2e24a6430897b21314cf27.jpg b/style-transform-master/style-transform-master/public/uploads/176b34907171b5597171b2e24a6430897b21314cf27.jpg new file mode 100644 index 0000000..79b5cdb Binary files /dev/null and b/style-transform-master/style-transform-master/public/uploads/176b34907171b5597171b2e24a6430897b21314cf27.jpg differ diff --git a/style-transform-master/style-transform-master/public/uploads/1c9986aaecb7d17aaddbeaaeb006e37f b/style-transform-master/style-transform-master/public/uploads/24140d7a8f001e552893569e61c45022 similarity index 100% rename from style-transform-master/style-transform-master/public/uploads/1c9986aaecb7d17aaddbeaaeb006e37f rename to style-transform-master/style-transform-master/public/uploads/24140d7a8f001e552893569e61c45022 diff --git a/style-transform-master/style-transform-master/public/uploads/332d42af8f74e985fb1571620b4a860b b/style-transform-master/style-transform-master/public/uploads/248baa6862e643126e7cc271f5c0db43 similarity index 100% rename from style-transform-master/style-transform-master/public/uploads/332d42af8f74e985fb1571620b4a860b rename to style-transform-master/style-transform-master/public/uploads/248baa6862e643126e7cc271f5c0db43 diff --git a/style-transform-master/style-transform-master/public/uploads/4b1e4e9c4e4fbe9de78602e683b21ba6 b/style-transform-master/style-transform-master/public/uploads/31cb74097c0f137cda202f97fc82c39c similarity index 100% rename from style-transform-master/style-transform-master/public/uploads/4b1e4e9c4e4fbe9de78602e683b21ba6 rename to style-transform-master/style-transform-master/public/uploads/31cb74097c0f137cda202f97fc82c39c diff --git a/style-transform-master/style-transform-master/public/uploads/34c21eb4ab6d5f21fe38e0e7c5e0bc51 b/style-transform-master/style-transform-master/public/uploads/40bf7fff77f209858c92692c1643db05 similarity index 100% rename from style-transform-master/style-transform-master/public/uploads/34c21eb4ab6d5f21fe38e0e7c5e0bc51 rename to style-transform-master/style-transform-master/public/uploads/40bf7fff77f209858c92692c1643db05 diff --git a/style-transform-master/style-transform-master/public/uploads/cc3197b0d46fdb5831763b680c3ace57 b/style-transform-master/style-transform-master/public/uploads/4a528c2b3d548f21efd498d6fcc6ee3e similarity index 100% rename from style-transform-master/style-transform-master/public/uploads/cc3197b0d46fdb5831763b680c3ace57 rename to style-transform-master/style-transform-master/public/uploads/4a528c2b3d548f21efd498d6fcc6ee3e diff --git a/style-transform-master/style-transform-master/public/uploads/266574aed51b4b86b16df83ce27ef93d b/style-transform-master/style-transform-master/public/uploads/6be77319ed4f40cb3764c9d17a0e3e6d similarity index 100% rename from style-transform-master/style-transform-master/public/uploads/266574aed51b4b86b16df83ce27ef93d rename to style-transform-master/style-transform-master/public/uploads/6be77319ed4f40cb3764c9d17a0e3e6d diff --git a/style-transform-master/style-transform-master/public/uploads/cdd8721916bc1b41e4de3a3c406953cd b/style-transform-master/style-transform-master/public/uploads/7b5ee265b28a6127e1655142523c6ce4 similarity index 100% rename from style-transform-master/style-transform-master/public/uploads/cdd8721916bc1b41e4de3a3c406953cd rename to style-transform-master/style-transform-master/public/uploads/7b5ee265b28a6127e1655142523c6ce4 diff --git a/style-transform-master/style-transform-master/public/uploads/f08b08ca187fecef6f70582cc988d459 b/style-transform-master/style-transform-master/public/uploads/9529e38e01e4ade24d1939ae029ea7ba similarity index 100% rename from style-transform-master/style-transform-master/public/uploads/f08b08ca187fecef6f70582cc988d459 rename to style-transform-master/style-transform-master/public/uploads/9529e38e01e4ade24d1939ae029ea7ba diff --git a/style-transform-master/style-transform-master/public/uploads/32a9eb5edee2387c3e20c301679db380 b/style-transform-master/style-transform-master/public/uploads/a0e8ff26bdf39d016052c3338fd11ab9 similarity index 100% rename from style-transform-master/style-transform-master/public/uploads/32a9eb5edee2387c3e20c301679db380 rename to style-transform-master/style-transform-master/public/uploads/a0e8ff26bdf39d016052c3338fd11ab9 diff --git a/style-transform-master/style-transform-master/public/uploads/a66b7d24b2ae85efd87692b33e8e69d1 b/style-transform-master/style-transform-master/public/uploads/a66b7d24b2ae85efd87692b33e8e69d1 new file mode 100644 index 0000000..dd27b85 Binary files /dev/null and b/style-transform-master/style-transform-master/public/uploads/a66b7d24b2ae85efd87692b33e8e69d1 differ diff --git a/style-transform-master/style-transform-master/public/uploads/b68ae966a5ac0ce4ef5c59feff613a2e b/style-transform-master/style-transform-master/public/uploads/b68ae966a5ac0ce4ef5c59feff613a2e new file mode 100644 index 0000000..dd27b85 Binary files /dev/null and b/style-transform-master/style-transform-master/public/uploads/b68ae966a5ac0ce4ef5c59feff613a2e differ diff --git a/style-transform-master/style-transform-master/public/uploads/d69579c100d6143a74359598b5277cc9 b/style-transform-master/style-transform-master/public/uploads/c0c0d564976eb7c53c1436be2333f31e similarity index 100% rename from style-transform-master/style-transform-master/public/uploads/d69579c100d6143a74359598b5277cc9 rename to style-transform-master/style-transform-master/public/uploads/c0c0d564976eb7c53c1436be2333f31e diff --git a/style-transform-master/style-transform-master/public/uploads/caa0e5cfcb3f4597e4c0ed7790275f31 b/style-transform-master/style-transform-master/public/uploads/caa0e5cfcb3f4597e4c0ed7790275f31 new file mode 100644 index 0000000..e9fce34 Binary files /dev/null and b/style-transform-master/style-transform-master/public/uploads/caa0e5cfcb3f4597e4c0ed7790275f31 differ diff --git a/style-transform-master/style-transform-master/public/uploads/ce4073057a801b2ca993fb1469a15e99 b/style-transform-master/style-transform-master/public/uploads/ce4073057a801b2ca993fb1469a15e99 new file mode 100644 index 0000000..e9fce34 Binary files /dev/null and b/style-transform-master/style-transform-master/public/uploads/ce4073057a801b2ca993fb1469a15e99 differ diff --git a/style-transform-master/style-transform-master/public/uploads/d517817f8cfc575b5a80563ff5359cd3 b/style-transform-master/style-transform-master/public/uploads/d517817f8cfc575b5a80563ff5359cd3 deleted file mode 100644 index 28b9ebf..0000000 Binary files a/style-transform-master/style-transform-master/public/uploads/d517817f8cfc575b5a80563ff5359cd3 and /dev/null differ diff --git a/style-transform-master/style-transform-master/public/uploads/d6a0e417d27ad4937da8f0ce7a826fd4 b/style-transform-master/style-transform-master/public/uploads/d6a0e417d27ad4937da8f0ce7a826fd4 new file mode 100644 index 0000000..e9fce34 Binary files /dev/null and b/style-transform-master/style-transform-master/public/uploads/d6a0e417d27ad4937da8f0ce7a826fd4 differ diff --git a/style-transform-master/style-transform-master/public/uploads/e634459ff4fd2d759b4691375f922723 b/style-transform-master/style-transform-master/public/uploads/e634459ff4fd2d759b4691375f922723 new file mode 100644 index 0000000..dd27b85 Binary files /dev/null and b/style-transform-master/style-transform-master/public/uploads/e634459ff4fd2d759b4691375f922723 differ diff --git a/style-transform-master/style-transform-master/public/uploads/876ae07ab5531800fbcabcdca5e507a2 b/style-transform-master/style-transform-master/public/uploads/f8abae0975cdc75a23d08fdf7c22b90c similarity index 100% rename from style-transform-master/style-transform-master/public/uploads/876ae07ab5531800fbcabcdca5e507a2 rename to style-transform-master/style-transform-master/public/uploads/f8abae0975cdc75a23d08fdf7c22b90c diff --git a/style-transform-master/style-transform-master/public/uploads/fe5269e79229d462114741c0ffadf28a b/style-transform-master/style-transform-master/public/uploads/fe5269e79229d462114741c0ffadf28a new file mode 100644 index 0000000..dd27b85 Binary files /dev/null and b/style-transform-master/style-transform-master/public/uploads/fe5269e79229d462114741c0ffadf28a differ diff --git a/style-transform-master/style-transform-master/server.js b/style-transform-master/style-transform-master/server.js index 2adcc97..4ca1be4 100644 --- a/style-transform-master/style-transform-master/server.js +++ b/style-transform-master/style-transform-master/server.js @@ -28,26 +28,19 @@ var upload = multer({ dest: 'public/uploads/' }); var progress = {}; 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(`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) { let args = data.split(' '); let signal = args[0]; @@ -69,8 +62,6 @@ server.post('/generate', upload.fields([{ name: 'content_image', maxCount: 1 }, progress[taskID].totalLoss = totalLoss; progress[taskID].ContentLoss = ContentLoss; progress[taskID].StyleLoss = StyleLoss; - - //console.log(taskID + ": " + args); }); child.on("close", (code) => { @@ -80,11 +71,45 @@ server.post('/generate', upload.fields([{ name: 'content_image', maxCount: 1 }, progress[taskID].status = -1; } 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")); - $('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.end($.html()); @@ -108,12 +133,17 @@ server.get('/success', 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) { - 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); } }); diff --git a/style-transform-master/style-transform-master/style-transform-master.njsproj b/style-transform-master/style-transform-master/style-transform-master.njsproj index cb777b7..5dfde67 100644 --- a/style-transform-master/style-transform-master/style-transform-master.njsproj +++ b/style-transform-master/style-transform-master/style-transform-master.njsproj @@ -28,6 +28,9 @@ true + + Code +