Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. const spawnSync = require('spawn-sync');
  2. const walk = require('walk');
  3. const url = require("url");
  4. const fs = require('fs');
  5. const learnRounds = 500;
  6.  
  7. var walker = walk.walk('./images/in', { followLinks: false });
  8.  
  9. walker.on('file', function(root, stat, next) {
  10. var path = root.replace("./images/in", "");
  11. var folderPath = path + '/' + stat.name;
  12. var totalPath = folderPath.replace(/ /g,"\\ ");
  13. console.log('Total: ' + totalPath);
  14.  
  15. if (!fs.existsSync("images/out"+path)) {
  16. fs.mkdirSync("images/out"+path);
  17. console.log("Created images/out"+path);
  18. } else {
  19. console.log("Skipping creation of images/out"+path);
  20. }
  21.  
  22. if (!fs.existsSync('images/out/' + totalPath)) {
  23.  
  24. var result = spawnSync('th', [
  25. 'neural_style.lua',
  26. '-style_image',
  27. 'images/style.jpg',
  28. '-content_image',
  29. 'images/in' + totalPath,
  30. '-gpu',
  31. '0',
  32. '-backend',
  33. 'cudnn',
  34. '-output_image',
  35. 'images/out/' + totalPath,
  36. '-num_iterations',
  37. learnRounds // 500
  38. ], {input: ''});
  39.  
  40. if (result.status !== 0) {
  41. next();
  42. } else {
  43. next();
  44. }
  45. } else {
  46. console.log("File exists in out, skipping");
  47. next();
  48. }
  49. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement