MCPcopy Create free account
hub / github.com/buaacxf/VIPTR / __getitem__

Method __getitem__

dataload/loader.py:49–72  ·  view source on GitHub ↗
(self, index)

Source from the content-addressed store, hash-verified

47 return self.nSamples
48
49 def __getitem__(self, index):
50 assert index <= len(self), 'index range error'
51 index += 1
52 with self.env.begin(write=False) as txn:
53 img_key = 'image-%09d' % index
54 imgbuf = txn.get(img_key.encode('utf-8'))
55 buf = six.BytesIO()
56 buf.write(imgbuf)
57 buf.seek(0)
58 try:
59 img = Image.open(buf).convert('RGB')
60 except IOError:
61 print('Corrupted image for %d' % index)
62 return self[index + 1]
63
64 label_key = 'label-%09d' % index
65 label = txn.get(label_key.encode('utf-8')).decode().replace('\ufeff', '').replace('\u3000', '').strip()
66 if self.fixKey:
67 if self.fixKeyType == 'En':
68 label = fixkeyEn(label)
69 label = label.lower()
70 elif self.fixKeyType == 'Ch':
71 label = fixkeyCh(label)
72 return (img, label)
73
74
75class resizeNormalize(object):

Callers

nothing calls this directly

Calls 4

fixkeyEnFunction · 0.85
fixkeyChFunction · 0.85
encodeMethod · 0.45
decodeMethod · 0.45

Tested by

no test coverage detected