MCPcopy Create free account
hub / github.com/cvlab-kaist/Talk3D / evaluate

Method evaluate

eval/syncnet_python/SyncNetInstance.py:42–148  ·  view source on GitHub ↗
(self, opt, videofile)

Source from the content-addressed store, hash-verified

40 self.__S__ = S(num_layers_in_fc_layers = num_layers_in_fc_layers).cuda();
41
42 def evaluate(self, opt, videofile):
43
44 self.__S__.eval();
45
46 # ========== ==========
47 # Convert files
48 # ========== ==========
49
50 if os.path.exists(os.path.join(opt.tmp_dir,opt.reference)):
51 rmtree(os.path.join(opt.tmp_dir,opt.reference))
52
53 os.makedirs(os.path.join(opt.tmp_dir,opt.reference))
54
55 command = ("ffmpeg -y -i %s -threads 1 -f image2 %s" % (videofile,os.path.join(opt.tmp_dir,opt.reference,'%06d.jpg')))
56 output = subprocess.call(command, shell=True, stdout=None)
57
58 command = ("ffmpeg -y -i %s -async 1 -ac 1 -vn -acodec pcm_s16le -ar 16000 %s" % (videofile,os.path.join(opt.tmp_dir,opt.reference,'audio.wav')))
59 output = subprocess.call(command, shell=True, stdout=None)
60
61 # ========== ==========
62 # Load video
63 # ========== ==========
64
65 images = []
66
67 flist = glob.glob(os.path.join(opt.tmp_dir,opt.reference,'*.jpg'))
68 flist.sort()
69
70 for fname in flist:
71 images.append(cv2.imread(fname))
72
73 im = numpy.stack(images,axis=3)
74 im = numpy.expand_dims(im,axis=0)
75 im = numpy.transpose(im,(0,3,4,1,2))
76
77 imtv = torch.autograd.Variable(torch.from_numpy(im.astype(float)).float())
78
79 # ========== ==========
80 # Load audio
81 # ========== ==========
82
83 sample_rate, audio = wavfile.read(os.path.join(opt.tmp_dir,opt.reference,'audio.wav'))
84 mfcc = zip(*python_speech_features.mfcc(audio,sample_rate))
85 mfcc = numpy.stack([numpy.array(i) for i in mfcc])
86
87 cc = numpy.expand_dims(numpy.expand_dims(mfcc,axis=0),axis=0)
88 cct = torch.autograd.Variable(torch.from_numpy(cc.astype(float)).float())
89
90 # ========== ==========
91 # Check audio and video input length
92 # ========== ==========
93
94 if (float(len(audio))/16000) != (float(len(images))/25) :
95 print("WARNING: Audio (%.4fs) and video (%.4fs) lengths are different."%(float(len(audio))/16000,float(len(images))/25))
96
97 min_length = min(len(images),math.floor(len(audio)/640))
98
99 # ========== ==========

Callers 4

demo_syncnet.pyFile · 0.45
run_syncnet.pyFile · 0.45

Calls 6

evalMethod · 0.80
appendMethod · 0.80
forward_lipMethod · 0.80
forward_audMethod · 0.80
calc_pdistFunction · 0.70
meanMethod · 0.45

Tested by

no test coverage detected