Skip to content

Commit d1a8937

Browse files
author
min.du
committed
update hdfs
1 parent 63ffe84 commit d1a8937

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

src/cocozip/io.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ def imread(filename, flags=cv2.IMREAD_COLOR, zip_file=None):
3535
path_zip = path[0: pos_at]
3636
path_img = zip_name + path[pos_at + 1:]
3737

38+
if path_zip.startswith('hdfs://'):
39+
_path_zip = os.path.basename(path_zip)
40+
if not os.path.exists(_path_zip):
41+
cmd = 'hadoop fs -get %s' % path_zip
42+
print(cmd)
43+
os.system(cmd)
44+
path_zip = _path_zip
45+
3846
if not os.path.isfile(path_zip):
3947
print("zip file '%s' is not found"%(path_zip))
4048
assert 0

src/cocozip/torchvision.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ def __init__(self, root, annFile,
1717
super(CocoDetection, self).__init__(root, annFile,
1818
transform, target_transform, transforms)
1919
self.zip_file = zip_file
20-
if zip_file.startswith('hdfs://'):
21-
cmd = 'hdfs fs -get %s' % zip_file
22-
os.system(cmd)
23-
self.zip_file = os.path.basename(zip_file)
2420

2521
def __getitem__(self, index):
2622
try:
415 Bytes
Binary file not shown.

tests/test_basic.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ def test_imread(self):
2626
print(img.shape, img2.shape)
2727
break
2828

29+
def test_imread_hdfs(self):
30+
coco_anno = '/home/public_data/min.du/coco2017/annotations/instances_val2017.json'
31+
zip_file = 'hdfs://hobot-bigdata/user/min.du/gpu004/public/coco/zip/val2017.zip'
32+
coco = COCO(coco_anno)
33+
image_ids = coco.getImgIds()
34+
for index in image_ids[:100]:
35+
file_name = '%012d.jpg' % index
36+
img = cocozip.imread(file_name, zip_file=zip_file)
37+
os.system('rm val2017.zip')
38+
2939
def test_imread_speed(self):
3040
coco_anno = '/home/public_data/min.du/coco2017/annotations/instances_train2017.json'
3141
imgdir = '/home/public_data/min.du/coco2017/images/train2017'

0 commit comments

Comments
 (0)