-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Update] Update MAE Pretraining part
- Loading branch information
1 parent
a2c174f
commit 0b37d73
Showing
9 changed files
with
185 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,6 @@ baselines/ | |
dataset_funcs/ | ||
mmocr-dev-1.x/work_dirs | ||
add_data/ | ||
mmocr-0.x/ | ||
mmocr-0.x/ | ||
mae/output_dir | ||
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import lmdb | ||
import sys | ||
import six | ||
from torch.utils.data import Dataset | ||
from PIL import Image | ||
|
||
|
||
class lmdbDataset(Dataset): | ||
"""LMDB dataset for raw images. | ||
Args: | ||
root (str): Root path for lmdb files. | ||
transform (callable, optional): A function/transform that takes in an | ||
PIL image and returns a transformed version. | ||
""" | ||
|
||
def __init__(self, root: str = None, transform=None): | ||
self.env = lmdb.open( | ||
root, | ||
max_readers=1, | ||
readonly=True, | ||
lock=False, | ||
readahead=False, | ||
meminit=False) | ||
|
||
if not self.env: | ||
print('cannot creat lmdb from %s' % (root)) | ||
sys.exit(0) | ||
|
||
with self.env.begin(write=False) as txn: | ||
nSamples = int(txn.get('num-samples'.encode())) | ||
self.nSamples = nSamples | ||
self.transform = transform | ||
|
||
def __len__(self): | ||
return self.nSamples | ||
|
||
def __getitem__(self, index): | ||
assert index <= len(self), 'index range error' | ||
index += 1 | ||
with self.env.begin(write=False) as txn: | ||
img_key = 'image-%09d' % index | ||
imgbuf = txn.get(img_key.encode()) | ||
|
||
buf = six.BytesIO() | ||
buf.write(imgbuf) | ||
buf.seek(0) | ||
try: | ||
img = Image.open(buf).convert('RGB') | ||
except IOError: | ||
print('Corrupted image for %d' % index) | ||
return self[index + 1] | ||
|
||
img = self.transform(img) | ||
|
||
return img, 'test' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
timm==0.3.2 | ||
tensorboard==2.11.0 | ||
lmdb==1.4.1 | ||
numpy<=1.23.0 |
Binary file not shown.
Binary file not shown.
Binary file not shown.