Exemplo n.º 1
0
 def enumerate_align_hash(self, video_list):
     align_hash = {}
     for video_path in video_list:
         video_id = os.path.splitext(video_path)[0].split('/')[-1]
         align_path = os.path.join(self.align_path, video_id)+".align"
         align_hash[video_id] = Align(self.absolute_max_string_len, text_to_labels).from_file(align_path)
     return align_hash
Exemplo n.º 2
0
 def enumerate_align_hash(self, video_list):
     align_hash = {}
     videos_to_remove = []
     for video_path in video_list:
         try:
             video_id = os.path.splitext(video_path)[0].split('/')[-1]
             align_path = os.path.join(self.align_path, video_id) + ".align"
             align_hash[video_id] = Align(
                 self.absolute_max_string_len,
                 text_to_labels).from_file(align_path)
         except Exception as e:
             videos_to_remove.append(video_path)
     return align_hash, videos_to_remove
Exemplo n.º 3
0
 def split_words(video, align):
     video_aligns = []
     for sub in align.align:
         # Create new video
         _video = Video(video.vtype, video.face_predictor_path)
         _video.face = video.face[sub[0]:sub[1]]
         _video.mouth = video.mouth[sub[0]:sub[1]]
         _video.set_data(_video.mouth)
         # Create new align
         _align = Align(align.absolute_max_string_len, align.label_func).from_array([(0, sub[1]-sub[0], sub[2])])
         # Append
         video_aligns.append((_video, _align))
     return video_aligns
Exemplo n.º 4
0
 def merge(video_aligns):
     vsample = video_aligns[0][0]
     asample = video_aligns[0][1]
     video = Video(vsample.vtype, vsample.face_predictor_path)
     video.face = np.ones((0, vsample.face.shape[1], vsample.face.shape[2], vsample.face.shape[3]), dtype=np.uint8)
     video.mouth = np.ones((0, vsample.mouth.shape[1], vsample.mouth.shape[2], vsample.mouth.shape[3]), dtype=np.uint8)
     align = []
     inc = 0
     for _video, _align in video_aligns:
         video.face = np.concatenate((video.face, _video.face), 0)
         video.mouth = np.concatenate((video.mouth, _video.mouth), 0)
         for sub in _align.align:
             _sub = (sub[0]+inc, sub[1]+inc, sub[2])
             align.append(_sub)
         inc = align[-1][1]
     video.set_data(video.mouth)
     align = Align(asample.absolute_max_string_len, asample.label_func).from_array(align)
     return (video, align)
Exemplo n.º 5
0
    print _align.padded_label
    print _align.label_length
    print np.array_equiv(_align.sentence, align.sentence),
    print np.array_equiv(_align.label, align.label),
    print np.array_equiv(_align.padded_label, align.padded_label)


curriculum = Curriculum(rules)

video = Video(vtype='face',
              face_predictor_path=
              'evaluation/models/shape_predictor_68_face_landmarks.dat')
video.from_video('evaluation/samples/id2_vcd_swwp2s.mpg')

align = Align(
    absolute_max_string_len=32,
    label_func=text_to_labels).from_file('evaluation/samples/swwp2s.align')

print "=== TRAINING ==="
for i in range(6):
    curriculum.update(i, train=True)
    print curriculum
    _video, _align, _ = curriculum.apply(video, align)
    show_results(_video, _align, video, align)

print "=== VALIDATION/TEST ==="
for i in range(6):
    curriculum.update(i, train=False)
    print curriculum
    _video, _align, _ = curriculum.apply(video, align)
    show_results(_video, _align, video, align)
Exemplo n.º 6
0
def get_align(align_url, video_length=75):
    align = Align(video_length, text_to_labels).from_file(align_url)
    return labels_to_text(align.padded_label.astype('int'))