-
Notifications
You must be signed in to change notification settings - Fork 32
/
eval-memoji.lua
65 lines (51 loc) · 1.91 KB
/
eval-memoji.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
--[[
This script grabs screenshots from a specified region of the screen, scores them with VGG Face against a folder of reference photos, and saves each captured image to a folder naming the file with its score. The script waits for you to hit enter on the keyboard for each capture.
--]]
-- The reference images that we want to match with the generated images
-- e.g. real world photos of people.
local refsFolder = "pics/obama"
local refsPattern = "*.png"
-- The x,y,w,h of the screen to grab with screen capture.
local grabRegion="145,70,190,190"
local grabFileName="screen.png"
-- The folder where scored images are stored.
local outFolder="out"
--
-- Main
--
require 'image'
require 'nn'
require 'image'
paths.dofile('util.lua')
paths.dofile('files.lua')
paths.dofile('compare.lua')
local pl = require('pl.import_into')() printf = pl.utils.printf
-- There shouldn't be any randomness involved here but I always do this.
torch.manualSeed(42)
net = torch.load('./torch_model/VGG_FACE.t7')
print(net)
net:evaluate()
-- The layers for which we will do the evaluation.
-- Layer 38 output is the 4096 element vector that characterizes the face, just before the prediction layer.
local selectedLayer = 38
-- Load the reference files
local refs = {}
local files = scandir(refsFolder, refsPattern)
for i,file in pairs(files) do
local refImg = process(image.load(file,3,'float'))
net:forward(refImg)
table.insert(refs,net.modules[selectedLayer].output:clone())
end
local count=0
while true do
grabImage(grabRegion, grabFileName)
-- Compare the references with each file in the targets folder
local result = compareFile(selectedLayer, refs, grabFileName)
print("result: ", result)
local img = image.load(grabFileName,3,'float')
image.save(outFolder..'/'..refsFolder..result.."-"..count..".jpg", img)
win=image.display{ image=img, legend="score: "..result, win=win }
print("hit enter")
readline()
count = count + 1
end