-
Notifications
You must be signed in to change notification settings - Fork 622
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Output text masks, upgrade dependencies, improved code and docs #155
Open
sslavian812
wants to merge
11
commits into
ankush-me:python3
Choose a base branch
from
sslavian812:python3
base: python3
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a10ace5
fix dependencies, fix deprecated matplotlib api useage. Saving masks …
sslavian812 28d4096
Implemented output-masks feature. fix style and documentation, fix de…
sslavian812 06e6de5
per-word bounding boxes and their labels added to file. added --debug…
sslavian812 68ad9aa
fix requirements.txt: added imageio dependency (scipy.misc.imsave is …
sslavian812 fe05aea
fix requirements.txt
sslavian812 53c9fd8
add timestamp to file names to make the unique
sslavian812 55a3ee3
raw data (h5 db and files) retrieval and provisioning moved to DataPr…
sslavian812 7b8cc58
use data provider api to access data instead of retrieving h5 d5 from it
sslavian812 e88959f
added flag to use data folder instead of default source
sslavian812 a38d9f4
fix bugs, add debug logs
sslavian812 08f19d3
fix bug
sslavian812 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,99 @@ | ||
import os | ||
from synthgen import * | ||
from common import * | ||
import wget | ||
import tarfile | ||
|
||
|
||
# TODO: move these contants inside DataProvider | ||
|
||
# path to the data-file, containing image, depth and segmentation: | ||
DATA_PATH = 'data' # TODO dedup | ||
DB_FNAME = osp.join(DATA_PATH, 'dset.h5') | ||
# url of the data (google-drive public file): | ||
DATA_URL = 'http://www.robots.ox.ac.uk/~ankush/data.tar.gz' | ||
|
||
|
||
class DateProvider(object): | ||
|
||
def __init__(self, root_data_dir=None): | ||
# TODO: add option to override those 3: | ||
path_depth = "depth.h5" | ||
path_segmap = "seg.h5" | ||
self.path_images = "bg_img" | ||
self.db = None | ||
self.depth_db = None | ||
self.seg_db = None | ||
self.segmap = {} | ||
self.depth = {} | ||
|
||
if root_data_dir is None: | ||
# should download default example | ||
self.db = DateProvider.get_data() | ||
self.segmap = self.db['seg'] | ||
self.depth = self.db['depth'] | ||
self.imnames = sorted(self.db['image'].keys()) | ||
else: | ||
# provided path to the folder with all data downloaded separately. | ||
# see https://github.com/ankush-me/SynthText#pre-processed-background-images | ||
self.path = root_data_dir | ||
self.depth_db = h5py.File(osp.join(self.path, path_depth), 'r') | ||
self.seg_db = h5py.File(osp.join(self.path, path_segmap), 'r') | ||
self.imnames = sorted(self.depth_db.keys()) | ||
self.segmap = self.seg_db['mask'] | ||
self.depth = self.depth_db | ||
|
||
@staticmethod | ||
def get_data(): | ||
""" | ||
Downloads the archive using link specified in DATA_URL. Unpacks the archive, treats it as h5 database. | ||
The image, depth and segmentation data is downloaded. | ||
|
||
Returns: | ||
the h5 database. | ||
""" | ||
if not osp.exists(DB_FNAME): | ||
try: | ||
colorprint(Color.BLUE, '\tdownloading data (56 M) from: ' + DATA_URL, bold=True) | ||
print() | ||
sys.stdout.flush() | ||
out_fname = 'data.tar.gz' | ||
wget.download(DATA_URL, out=out_fname) | ||
tar = tarfile.open(out_fname) | ||
tar.extractall() | ||
tar.close() | ||
os.remove(out_fname) | ||
colorprint(Color.BLUE, '\n\tdata saved at:' + DB_FNAME, bold=True) | ||
sys.stdout.flush() | ||
except: | ||
print(colorize(Color.RED, 'Data not found and have problems downloading.', bold=True)) | ||
sys.stdout.flush() | ||
sys.exit(-1) | ||
# open the h5 file and return: | ||
return h5py.File(DB_FNAME, 'r') | ||
|
||
def get_image(self, imname: str): | ||
if self.db is None: | ||
return Image.open(osp.join(self.path, self.path_images, imname)).convert('RGB') | ||
else: | ||
return Image.fromarray(self.db['image'][imname][:]) | ||
|
||
def get_segmap(self, imname: str): | ||
return self.segmap[imname] | ||
|
||
def get_depth(self, imname: str): | ||
if self.db is None: | ||
return self.depth[imname][:].T[:, :, 0] | ||
else: | ||
return self.depth[imname][:].T[:, :, 1] | ||
|
||
def get_imnames(self): | ||
return self.imnames | ||
|
||
def close(self): | ||
if self.db is not None: | ||
self.db.close() | ||
if self.depth_db is not None: | ||
self.depth_db.close() | ||
if self.seg_db is not None: | ||
self.seg_db.close() |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there seem to be two data_paths --
data_path
andDATA_PATH
?