generate_dataset.lua 887 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/usr/bin/env th
  2. local threads = require 'threads'
  3. local nthread = 8
  4. local njob = 100000
  5. local pool = threads.Threads(
  6. nthread,
  7. function(threadid)
  8. end
  9. )
  10. local jobdone = 56530
  11. for i=jobdone,njob do
  12. pool:addjob(
  13. function()
  14. require "image"
  15. gen = require("DungeonGenerator")
  16. gen.DIMENSION=64
  17. tensor = torch.Tensor(1, gen.DIMENSION, gen.DIMENSION)
  18. m = gen.generate(i)
  19. index = 1
  20. for y=0,gen.DIMENSION-1 do
  21. for x=0,gen.DIMENSION-1 do
  22. tensor:storage()[index] = m.tiles[y][x]
  23. index = index+1
  24. end
  25. end
  26. image.save(("out/%06d.png"):format(i), tensor)
  27. return __threadid
  28. end,
  29. function(id)
  30. jobdone = jobdone + 1
  31. print(("%d pictures generated"):format(jobdone))
  32. end )
  33. end
  34. pool:synchronize()
  35. pool:terminate()