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

Method extract_feature

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

Source from the content-addressed store, hash-verified

148 return offset.numpy(), conf.numpy(), dists_npy
149
150 def extract_feature(self, opt, videofile):
151
152 self.__S__.eval();
153
154 # ========== ==========
155 # Load video
156 # ========== ==========
157 cap = cv2.VideoCapture(videofile)
158
159 frame_num = 1;
160 images = []
161 while frame_num:
162 frame_num += 1
163 ret, image = cap.read()
164 if ret == 0:
165 break
166
167 images.append(image)
168
169 im = numpy.stack(images,axis=3)
170 im = numpy.expand_dims(im,axis=0)
171 im = numpy.transpose(im,(0,3,4,1,2))
172
173 imtv = torch.autograd.Variable(torch.from_numpy(im.astype(float)).float())
174
175 # ========== ==========
176 # Generate video feats
177 # ========== ==========
178
179 lastframe = len(images)-4
180 im_feat = []
181
182 tS = time.time()
183 for i in range(0,lastframe,opt.batch_size):
184
185 im_batch = [ imtv[:,:,vframe:vframe+5,:,:] for vframe in range(i,min(lastframe,i+opt.batch_size)) ]
186 im_in = torch.cat(im_batch,0)
187 im_out = self.__S__.forward_lipfeat(im_in.cuda());
188 im_feat.append(im_out.data.cpu())
189
190 im_feat = torch.cat(im_feat,0)
191
192 # ========== ==========
193 # Compute offset
194 # ========== ==========
195
196 print('Compute time %.3f sec.' % (time.time()-tS))
197
198 return im_feat
199
200
201 def loadParameters(self, path):

Callers 1

demo_feature.pyFile · 0.45

Calls 3

evalMethod · 0.80
appendMethod · 0.80
forward_lipfeatMethod · 0.80

Tested by

no test coverage detected