Skip to content

Commit e00d29b

Browse files
author
zyan3
committed
[video reader]remove logging. update setup.py
1 parent f71a4ba commit e00d29b

File tree

2 files changed

+6
-53
lines changed

2 files changed

+6
-53
lines changed

setup.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ def get_extensions():
121121
include_dirs = [extensions_dir]
122122
tests_include_dirs = [test_dir, models_dir]
123123

124+
# Packages install by conda will put header files in the include folder of
125+
# conda virtual environment
126+
conda_prefix = os.environ.get('CONDA_PREFIX')
127+
conda_include_dir = os.path.join(conda_prefix, 'include')
128+
124129
# TorchVision video reader
125130
video_reader_src_dir = os.path.join(this_dir, 'torchvision', 'csrc', 'cpu', 'video_reader')
126131
video_reader_src = glob.glob(os.path.join(video_reader_src_dir, "*.cpp"))
@@ -145,6 +150,7 @@ def get_extensions():
145150
video_reader_src,
146151
include_dirs=[
147152
video_reader_src_dir,
153+
conda_include_dir,
148154
],
149155
libraries=[
150156
'glog',

test/test_video_reader.py

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import collections
22
from common_utils import get_tmp_dir
33
from fractions import Fraction
4-
import logging
54
import math
65
import numpy as np
76
import os
@@ -106,8 +105,6 @@
106105
torch.ops.load_library(lib_path)
107106
video_reader = torch.ops.video_reader
108107

109-
log = logging.getLogger(__name__)
110-
111108
DecoderResult = collections.namedtuple(
112109
"DecoderResult", "vframes vframe_pts vtimebase aframes aframe_pts atimebase"
113110
)
@@ -233,7 +230,6 @@ def _decode_frames_by_av_module(
233230
[audio_frame.pts for audio_frame in audio_frames], dtype=torch.int64
234231
)
235232

236-
log.error("Decode by PyAv. Elapsed time: %2.4f\n" % elapsed_time)
237233

238234
return DecoderResult(
239235
vframes=vframes,
@@ -343,7 +339,6 @@ def compare_decoding_result(self, tv_result, ref_result, config=all_check_config
343339
"By default, it is disabled"
344340
)
345341
def test_stress_test_read_video_from_file(self):
346-
log.error("\n\t===========stress test: read_video_from_file")
347342
num_iter = 10000
348343
# video related
349344
width, height, min_dimension = 0, 0, 0
@@ -355,10 +350,7 @@ def test_stress_test_read_video_from_file(self):
355350
audio_timebase_num, audio_timebase_den = 0, 1
356351

357352
for i in range(num_iter):
358-
if i % 100 == 0:
359-
log.error("%d / %d" % (i, num_iter))
360353
for test_video, config in test_videos.items():
361-
log.error("\nvideo: %s\n" % test_video)
362354
full_path = os.path.join(VIDEO_DIR, test_video)
363355

364356
# pass 1: decode all frames using new decoder
@@ -384,7 +376,6 @@ def test_stress_test_read_video_from_file(self):
384376

385377

386378
def test_read_video_from_file(self):
387-
log.error("\n\t===========test_read_video_from_file")
388379
"""
389380
Test the case when decoder starts with a video file to decode frames.
390381
"""
@@ -398,7 +389,6 @@ def test_read_video_from_file(self):
398389
audio_timebase_num, audio_timebase_den = 0, 1
399390

400391
for test_video, config in test_videos.items():
401-
log.error("\nvideo: %s\n" % test_video)
402392
full_path = os.path.join(VIDEO_DIR, test_video)
403393

404394
# pass 1: decode all frames using new decoder
@@ -422,9 +412,6 @@ def test_read_video_from_file(self):
422412
audio_timebase_den,
423413
)
424414
elapsed_time = time.perf_counter() - start_time
425-
log.error(
426-
"TorchVision decoder. Elapsed time: %2.4f\n" % elapsed_time
427-
)
428415
# pass 2: decode all frames using av
429416
pyav_result = _decode_frames_by_av_module(full_path)
430417
# check results from TorchVision decoder
@@ -433,7 +420,6 @@ def test_read_video_from_file(self):
433420
self.compare_decoding_result(tv_result, pyav_result, config)
434421

435422
def test_read_video_from_file_rescale_min_dimension(self):
436-
log.error("\n\t===========test_read_video_from_file_rescale_min_dimension")
437423
"""
438424
Test the case when decoder starts with a video file to decode frames, and
439425
video min dimension between height and width is set.
@@ -448,7 +434,6 @@ def test_read_video_from_file_rescale_min_dimension(self):
448434
audio_timebase_num, audio_timebase_den = 0, 1
449435

450436
for test_video, config in test_videos.items():
451-
log.error("\nvideo: %s\n" % test_video)
452437
full_path = os.path.join(VIDEO_DIR, test_video)
453438

454439
start_time = time.perf_counter()
@@ -471,11 +456,9 @@ def test_read_video_from_file_rescale_min_dimension(self):
471456
audio_timebase_den,
472457
)
473458
elapsed_time = time.perf_counter() - start_time
474-
log.error("TorchVision decoder. Elapsed time: %2.4f\n" % elapsed_time)
475459
self.assertEqual(min_dimension, min(tv_result[0].size(1), tv_result[0].size(2)))
476460

477461
def test_read_video_from_file_rescale_width(self):
478-
log.error("\n\t===========test_read_video_from_file_rescale_width")
479462
"""
480463
Test the case when decoder starts with a video file to decode frames, and
481464
video width is set.
@@ -490,7 +473,6 @@ def test_read_video_from_file_rescale_width(self):
490473
audio_timebase_num, audio_timebase_den = 0, 1
491474

492475
for test_video, config in test_videos.items():
493-
log.error("\nvideo: %s\n" % test_video)
494476
full_path = os.path.join(VIDEO_DIR, test_video)
495477

496478
start_time = time.perf_counter()
@@ -513,11 +495,9 @@ def test_read_video_from_file_rescale_width(self):
513495
audio_timebase_den,
514496
)
515497
elapsed_time = time.perf_counter() - start_time
516-
log.error("TorchVision decoder. Elapsed time: %2.4f\n" % elapsed_time)
517498
self.assertEqual(tv_result[0].size(2), width)
518499

519500
def test_read_video_from_file_rescale_height(self):
520-
log.error("\n\t===========test_read_video_from_file_rescale_height")
521501
"""
522502
Test the case when decoder starts with a video file to decode frames, and
523503
video height is set.
@@ -532,7 +512,6 @@ def test_read_video_from_file_rescale_height(self):
532512
audio_timebase_num, audio_timebase_den = 0, 1
533513

534514
for test_video, config in test_videos.items():
535-
log.error("\nvideo: %s\n" % test_video)
536515
full_path = os.path.join(VIDEO_DIR, test_video)
537516

538517
start_time = time.perf_counter()
@@ -555,11 +534,9 @@ def test_read_video_from_file_rescale_height(self):
555534
audio_timebase_den,
556535
)
557536
elapsed_time = time.perf_counter() - start_time
558-
log.error("TorchVision decoder. Elapsed time: %2.4f\n" % elapsed_time)
559537
self.assertEqual(tv_result[0].size(1), height)
560538

561539
def test_read_video_from_file_rescale_width_and_height(self):
562-
log.error("\n\t===========test_read_video_from_file_rescale_width_and_height")
563540
"""
564541
Test the case when decoder starts with a video file to decode frames, and
565542
both video height and width are set.
@@ -574,7 +551,6 @@ def test_read_video_from_file_rescale_width_and_height(self):
574551
audio_timebase_num, audio_timebase_den = 0, 1
575552

576553
for test_video, config in test_videos.items():
577-
log.error("\nvideo: %s\n" % test_video)
578554
full_path = os.path.join(VIDEO_DIR, test_video)
579555

580556
start_time = time.perf_counter()
@@ -597,13 +573,11 @@ def test_read_video_from_file_rescale_width_and_height(self):
597573
audio_timebase_den,
598574
)
599575
elapsed_time = time.perf_counter() - start_time
600-
log.error("TorchVision decoder. Elapsed time: %2.4f\n" % elapsed_time)
601576
self.assertEqual(tv_result[0].size(1), height)
602577
self.assertEqual(tv_result[0].size(2), width)
603578

604579

605580
def test_read_video_from_file_audio_resampling(self):
606-
log.error("\n\t===========test_read_video_from_file_audio_resampling")
607581
"""
608582
Test the case when decoder starts with a video file to decode frames, and
609583
audio waveform are resampled
@@ -623,7 +597,6 @@ def test_read_video_from_file_audio_resampling(self):
623597
audio_timebase_num, audio_timebase_den = 0, 1
624598

625599
for test_video, config in test_videos.items():
626-
log.error("\nvideo: %s\n" % test_video)
627600
full_path = os.path.join(VIDEO_DIR, test_video)
628601

629602
tv_result = video_reader.read_video_from_file(
@@ -659,7 +632,6 @@ def test_read_video_from_file_audio_resampling(self):
659632
)
660633

661634
def test_compare_read_video_from_memory_and_file(self):
662-
log.error("\n\t===========test_compare_read_video_from_memory_and_file")
663635
"""
664636
Test the case when video is already in memory, and decoder reads data in memory
665637
"""
@@ -673,7 +645,6 @@ def test_compare_read_video_from_memory_and_file(self):
673645
audio_timebase_num, audio_timebase_den = 0, 1
674646

675647
for test_video, config in test_videos.items():
676-
log.error("\nvideo: %s\n" % test_video)
677648
full_path, video_tensor = _get_video_tensor(VIDEO_DIR, test_video)
678649

679650
# pass 1: decode all frames using cpp decoder
@@ -697,9 +668,6 @@ def test_compare_read_video_from_memory_and_file(self):
697668
audio_timebase_den,
698669
)
699670
elapsed_time = time.perf_counter() - start_time
700-
log.error(
701-
"TorchVision decoder. Elapsed time: %2.4f\n" % elapsed_time
702-
)
703671
self.check_separate_decoding_result(tv_result_memory, config)
704672
# pass 2: decode all frames from file
705673
start_time = time.perf_counter()
@@ -722,15 +690,13 @@ def test_compare_read_video_from_memory_and_file(self):
722690
audio_timebase_den,
723691
)
724692
elapsed_time = time.perf_counter() - start_time
725-
log.error("TorchVision decoder. Elapsed time: %2.4f\n" % elapsed_time)
726693

727694
self.check_separate_decoding_result(tv_result_file, config)
728695
# finally, compare results decoded from memory and file
729696
self.compare_decoding_result(tv_result_memory, tv_result_file)
730697

731698

732699
def test_read_video_from_file(self):
733-
log.error("\n\t===========test_read_video_from_file")
734700
"""
735701
Test the case when decoder starts with a video file to decode frames.
736702
"""
@@ -744,7 +710,6 @@ def test_read_video_from_file(self):
744710
audio_timebase_num, audio_timebase_den = 0, 1
745711

746712
for test_video, config in test_videos.items():
747-
log.error("\nvideo: %s\n" % test_video)
748713
full_path = os.path.join(VIDEO_DIR, test_video)
749714

750715
# pass 1: decode all frames using new decoder
@@ -768,7 +733,6 @@ def test_read_video_from_file(self):
768733
audio_timebase_den,
769734
)
770735
elapsed_time = time.perf_counter() - start_time
771-
log.error("TorchVision decoder. Elapsed time: %2.4f\n" % elapsed_time)
772736
# pass 2: decode all frames using av
773737
pyav_result = _decode_frames_by_av_module(full_path)
774738

@@ -777,7 +741,6 @@ def test_read_video_from_file(self):
777741
self.compare_decoding_result(tv_result, pyav_result, config)
778742

779743
def test_read_video_from_memory(self):
780-
log.error("\n\t===========test_read_video_from_memory")
781744
"""
782745
Test the case when video is already in memory, and decoder reads data in memory
783746
"""
@@ -791,7 +754,6 @@ def test_read_video_from_memory(self):
791754
audio_timebase_num, audio_timebase_den = 0, 1
792755

793756
for test_video, config in test_videos.items():
794-
log.error("\nvideo: %s\n" % test_video)
795757
full_path, video_tensor = _get_video_tensor(VIDEO_DIR, test_video)
796758

797759
# pass 1: decode all frames using cpp decoder
@@ -815,15 +777,13 @@ def test_read_video_from_memory(self):
815777
audio_timebase_den,
816778
)
817779
elapsed_time = time.perf_counter() - start_time
818-
log.error("TorchVision decoder. Elapsed time: %2.4f\n" % elapsed_time)
819780
# pass 2: decode all frames using av
820781
pyav_result = _decode_frames_by_av_module(full_path)
821782

822783
self.check_separate_decoding_result(tv_result, config)
823784
self.compare_decoding_result(tv_result, pyav_result, config)
824785

825786
def test_read_video_from_memory_get_pts_only(self):
826-
log.error("\n\t===========test_read_video_from_memory_get_pts_only")
827787
"""
828788
Test the case when video is already in memory, and decoder reads data in memory.
829789
Compare frame pts between decoding for pts only and full decoding
@@ -839,7 +799,6 @@ def test_read_video_from_memory_get_pts_only(self):
839799
audio_timebase_num, audio_timebase_den = 0, 1
840800

841801
for test_video, config in test_videos.items():
842-
log.error("\nvideo: %s\n" % test_video)
843802
full_path, video_tensor = _get_video_tensor(VIDEO_DIR, test_video)
844803

845804
# pass 1: decode all frames using cpp decoder
@@ -863,7 +822,6 @@ def test_read_video_from_memory_get_pts_only(self):
863822
audio_timebase_den,
864823
)
865824
elapsed_time = time.perf_counter() - start_time
866-
log.error("getPtsOnly = 0. Elapsed time: %2.4f" % elapsed_time)
867825
self.assertAlmostEqual(config.video_fps, tv_result[3].item(), delta=0.01)
868826

869827
# pass 2: decode all frames to get PTS only using cpp decoder
@@ -887,21 +845,18 @@ def test_read_video_from_memory_get_pts_only(self):
887845
audio_timebase_den,
888846
)
889847
elapsed_time = time.perf_counter() - start_time
890-
log.error("getPtsOnly = 1. Elapsed time: %2.4f\n" % elapsed_time)
891848

892849
self.assertEqual(tv_result_pts_only[0].numel(), 0)
893850
self.assertEqual(tv_result_pts_only[4].numel(), 0)
894851
self.compare_decoding_result(tv_result, tv_result_pts_only)
895852

896853
def test_read_video_in_range_from_memory(self):
897-
log.error("\n\ttest_read_video_in_range_from_memory")
898854
"""
899855
Test the case when video is already in memory, and decoder reads data in memory.
900856
In addition, decoder takes meaningful start- and end PTS as input, and decode
901857
frames within that interval
902858
"""
903859
for test_video, config in test_videos.items():
904-
log.error("\nvideo: %s\n" % test_video)
905860
full_path, video_tensor = _get_video_tensor(VIDEO_DIR, test_video)
906861
# video related
907862
width, height, min_dimension = 0, 0, 0
@@ -935,16 +890,11 @@ def test_read_video_in_range_from_memory(self):
935890
tv_result
936891
)
937892
elapsed_time = time.perf_counter() - start_time
938-
log.error(
939-
"Decode whole video by TorchVision decoder. Elapsed time: %2.4f" % elapsed_time
940-
)
941893
self.assertAlmostEqual(config.video_fps, vfps.item(), delta=0.01)
942894

943895
for num_frames in [4, 8, 16, 32, 64, 128]:
944-
log.error("\nvideo: %s No. of frames: %d" % (test_video, num_frames))
945896
start_pts_ind_max = vframe_pts.size(0) - num_frames
946897
if start_pts_ind_max <= 0:
947-
log.error("Skip.")
948898
continue
949899
# randomly pick start pts
950900
start_pts_ind = randint(0, start_pts_ind_max)
@@ -990,9 +940,6 @@ def test_read_video_in_range_from_memory(self):
990940
audio_timebase_den,
991941
)
992942
elapsed_time = time.perf_counter() - start_time
993-
log.error(
994-
"TorchVision decoder. Elapsed time: %2.4f" % elapsed_time
995-
)
996943

997944
# pass 3: decode frames in range using PyAv
998945
video_timebase_av, audio_timebase_av = _get_timebase_by_av_module(full_path)

0 commit comments

Comments
 (0)