Skip to content
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

Add tqdm module #76

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions classes.txt

This file was deleted.

45 changes: 45 additions & 0 deletions label2yolo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import os

def labelChange(path_link):
label = 'Label'

#Customỉze class_id
class_id = 0

for v in os.listdir(path_link):
#Load link
file = os.path.join(path_link, v)
file = file + '/' #On ubuntu dont need this
file = os.path.join(file, label)
file = file + '/'

for i in os.listdir(file):
#Link labelfile
labelfile = os.path.join(file, i)

#Get lineString
f = open(labelfile, 'r')
i = f.readlines()
f.close()

#Replace string to class_id
f = open(labelfile, 'w')
for line in i:
#Load line and split
listString = line.split()
listString[0] = class_id #Replace string

list2String = ' '.join([str(elem) for elem in listString])
f.write(list2String)
f.write('\n')
f.close()
class_id += 1

#Link to pathfile, can customize it
train_link = 'OID/Dataset/train/'
test_link = 'OID/Dataset/test/'
val_link = 'OID/Dataset/validation/'

labelChange(train_link)
labelChange(test_link)
labelChange(val_link)
4 changes: 0 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
pandas
numpy
awscli

urllib3

tqdm

opencv-python
40 changes: 40 additions & 0 deletions tqdm/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from .std import tqdm, trange
from .gui import tqdm as tqdm_gui # TODO: remove in v5.0.0
from .gui import trange as tgrange # TODO: remove in v5.0.0
from ._tqdm_pandas import tqdm_pandas
from .cli import main # TODO: remove in v5.0.0
from ._monitor import TMonitor, TqdmSynchronisationWarning
from ._version import __version__ # NOQA
from .std import TqdmTypeError, TqdmKeyError, TqdmWarning, \
TqdmDeprecationWarning, TqdmExperimentalWarning, \
TqdmMonitorWarning

__all__ = ['tqdm', 'tqdm_gui', 'trange', 'tgrange', 'tqdm_pandas',
'tqdm_notebook', 'tnrange', 'main', 'TMonitor',
'TqdmTypeError', 'TqdmKeyError',
'TqdmWarning', 'TqdmDeprecationWarning',
'TqdmExperimentalWarning',
'TqdmMonitorWarning', 'TqdmSynchronisationWarning',
'__version__']


def tqdm_notebook(*args, **kwargs): # pragma: no cover
"""See tqdm.notebook.tqdm for full documentation"""
from .notebook import tqdm as _tqdm_notebook
from warnings import warn
warn("This function will be removed in tqdm==5.0.0\n"
"Please use `tqdm.notebook.tqdm` instead of `tqdm.tqdm_notebook`",
TqdmDeprecationWarning, stacklevel=2)
return _tqdm_notebook(*args, **kwargs)


def tnrange(*args, **kwargs): # pragma: no cover
"""
A shortcut for `tqdm.notebook.tqdm(xrange(*args), **kwargs)`.
On Python3+, `range` is used instead of `xrange`.
"""
from .notebook import trange as _tnrange
from warnings import warn
warn("Please use `tqdm.notebook.trange` instead of `tqdm.tnrange`",
TqdmDeprecationWarning, stacklevel=2)
return _tnrange(*args, **kwargs)
Binary file added tqdm/__init__.pyc
Binary file not shown.
2 changes: 2 additions & 0 deletions tqdm/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .cli import main
main()
Binary file added tqdm/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
Binary file added tqdm/__pycache__/_monitor.cpython-37.pyc
Binary file not shown.
Binary file added tqdm/__pycache__/_tqdm_pandas.cpython-37.pyc
Binary file not shown.
Binary file added tqdm/__pycache__/_version.cpython-37.pyc
Binary file not shown.
Binary file added tqdm/__pycache__/cli.cpython-37.pyc
Binary file not shown.
Binary file added tqdm/__pycache__/gui.cpython-37.pyc
Binary file not shown.
Binary file added tqdm/__pycache__/std.cpython-37.pyc
Binary file not shown.
Binary file added tqdm/__pycache__/utils.cpython-37.pyc
Binary file not shown.
7 changes: 7 additions & 0 deletions tqdm/_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from .cli import * # NOQA
from .cli import __all__ # NOQA
from .std import TqdmDeprecationWarning
from warnings import warn
warn("This function will be removed in tqdm==5.0.0\n"
"Please use `tqdm.cli.*` instead of `tqdm._main.*`",
TqdmDeprecationWarning, stacklevel=2)
99 changes: 99 additions & 0 deletions tqdm/_monitor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
from threading import Event, Thread, current_thread
from time import time
from warnings import warn
import atexit
__all__ = ["TMonitor", "TqdmSynchronisationWarning"]


class TqdmSynchronisationWarning(RuntimeWarning):
"""tqdm multi-thread/-process errors which may cause incorrect nesting
but otherwise no adverse effects"""
pass


class TMonitor(Thread):
"""
Monitoring thread for tqdm bars.
Monitors if tqdm bars are taking too much time to display
and readjusts miniters automatically if necessary.

Parameters
----------
tqdm_cls : class
tqdm class to use (can be core tqdm or a submodule).
sleep_interval : fload
Time to sleep between monitoring checks.
"""

# internal vars for unit testing
_time = None
_event = None

def __init__(self, tqdm_cls, sleep_interval):
Thread.__init__(self)
self.daemon = True # kill thread when main killed (KeyboardInterrupt)
self.was_killed = Event()
self.woken = 0 # last time woken up, to sync with monitor
self.tqdm_cls = tqdm_cls
self.sleep_interval = sleep_interval
if TMonitor._time is not None:
self._time = TMonitor._time
else:
self._time = time
if TMonitor._event is not None:
self._event = TMonitor._event
else:
self._event = Event
atexit.register(self.exit)
self.start()

def exit(self):
self.was_killed.set()
if self is not current_thread():
self.join()
return self.report()

def get_instances(self):
# returns a copy of started `tqdm_cls` instances
return [i for i in self.tqdm_cls._instances.copy()
# Avoid race by checking that the instance started
if hasattr(i, 'start_t')]

def run(self):
cur_t = self._time()
while True:
# After processing and before sleeping, notify that we woke
# Need to be done just before sleeping
self.woken = cur_t
# Sleep some time...
self.was_killed.wait(self.sleep_interval)
# Quit if killed
if self.was_killed.is_set():
return
# Then monitor!
# Acquire lock (to access _instances)
with self.tqdm_cls.get_lock():
cur_t = self._time()
# Check tqdm instances are waiting too long to print
instances = self.get_instances()
for instance in instances:
# Check event in loop to reduce blocking time on exit
if self.was_killed.is_set():
return
# Only if mininterval > 1 (else iterations are just slow)
# and last refresh exceeded maxinterval
if instance.miniters > 1 and \
(cur_t - instance.last_print_t) >= \
instance.maxinterval:
# force bypassing miniters on next iteration
# (dynamic_miniters adjusts mininterval automatically)
instance.miniters = 1
# Refresh now! (works only for manual tqdm)
instance.refresh(nolock=True)
if instances != self.get_instances(): # pragma: nocover
warn("Set changed size during iteration" +
" (see https://github.com/tqdm/tqdm/issues/481)",
TqdmSynchronisationWarning, stacklevel=2)

def report(self):
return not self.was_killed.is_set()
Binary file added tqdm/_monitor.pyc
Binary file not shown.
7 changes: 7 additions & 0 deletions tqdm/_tqdm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from .std import * # NOQA
from .std import __all__ # NOQA
from .std import TqdmDeprecationWarning
from warnings import warn
warn("This function will be removed in tqdm==5.0.0\n"
"Please use `tqdm.std.*` instead of `tqdm._tqdm.*`",
TqdmDeprecationWarning, stacklevel=2)
7 changes: 7 additions & 0 deletions tqdm/_tqdm_gui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from .gui import * # NOQA
from .gui import __all__ # NOQA
from .std import TqdmDeprecationWarning
from warnings import warn
warn("This function will be removed in tqdm==5.0.0\n"
"Please use `tqdm.gui.*` instead of `tqdm._tqdm_gui.*`",
TqdmDeprecationWarning, stacklevel=2)
7 changes: 7 additions & 0 deletions tqdm/_tqdm_notebook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from .notebook import * # NOQA
from .notebook import __all__ # NOQA
from .std import TqdmDeprecationWarning
from warnings import warn
warn("This function will be removed in tqdm==5.0.0\n"
"Please use `tqdm.notebook.*` instead of `tqdm._tqdm_notebook.*`",
TqdmDeprecationWarning, stacklevel=2)
46 changes: 46 additions & 0 deletions tqdm/_tqdm_pandas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import sys

__author__ = "github.com/casperdcl"
__all__ = ['tqdm_pandas']


def tqdm_pandas(tclass, *targs, **tkwargs):
"""
Registers the given `tqdm` instance with
`pandas.core.groupby.DataFrameGroupBy.progress_apply`.
It will even close() the `tqdm` instance upon completion.

Parameters
----------
tclass : tqdm class you want to use (eg, tqdm, tqdm_notebook, etc)
targs and tkwargs : arguments for the tqdm instance

Examples
--------
>>> import pandas as pd
>>> import numpy as np
>>> from tqdm import tqdm, tqdm_pandas
>>>
>>> df = pd.DataFrame(np.random.randint(0, 100, (100000, 6)))
>>> tqdm_pandas(tqdm, leave=True) # can use tqdm_gui, optional kwargs, etc
>>> # Now you can use `progress_apply` instead of `apply`
>>> df.groupby(0).progress_apply(lambda x: x**2)

References
----------
https://stackoverflow.com/questions/18603270/
progress-indicator-during-pandas-operations-python
"""
from tqdm import TqdmDeprecationWarning

if isinstance(tclass, type) or (getattr(tclass, '__name__', '').startswith(
'tqdm_')): # delayed adapter case
TqdmDeprecationWarning("""\
Please use `tqdm.pandas(...)` instead of `tqdm_pandas(tqdm, ...)`.
""", fp_write=getattr(tkwargs.get('file', None), 'write', sys.stderr.write))
tclass.pandas(*targs, **tkwargs)
else:
TqdmDeprecationWarning("""\
Please use `tqdm.pandas(...)` instead of `tqdm_pandas(tqdm(...))`.
""", fp_write=getattr(tclass.fp, 'write', sys.stderr.write))
type(tclass).pandas(deprecated_t=tclass)
Binary file added tqdm/_tqdm_pandas.pyc
Binary file not shown.
6 changes: 6 additions & 0 deletions tqdm/_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from .utils import CUR_OS, IS_WIN, IS_NIX, RE_ANSI, _range, _unich, _unicode, colorama, WeakSet, _basestring, _OrderedDict, FormatReplace, Comparable, SimpleTextIOWrapper, _is_utf, _supports_unicode, _is_ascii, _environ_cols_wrapper, _environ_cols_windows, _environ_cols_tput, _environ_cols_linux, _term_move_up # NOQA
from .std import TqdmDeprecationWarning
from warnings import warn
warn("This function will be removed in tqdm==5.0.0\n"
"Please use `tqdm.utils.*` instead of `tqdm._utils.*`",
TqdmDeprecationWarning, stacklevel=2)
59 changes: 59 additions & 0 deletions tqdm/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Definition of the version number
import os
from io import open as io_open

__all__ = ["__version__"]

# major, minor, patch, -extra
version_info = 4, 43, 0

# Nice string for the version
__version__ = '.'.join(map(str, version_info))


# auto -extra based on commit hash (if not tagged as release)
scriptdir = os.path.dirname(__file__)
gitdir = os.path.abspath(os.path.join(scriptdir, "..", ".git"))
if os.path.isdir(gitdir): # pragma: nocover
extra = None
# Open config file to check if we are in tqdm project
with io_open(os.path.join(gitdir, "config"), 'r') as fh_config:
if 'tqdm' in fh_config.read():
# Open the HEAD file
with io_open(os.path.join(gitdir, "HEAD"), 'r') as fh_head:
extra = fh_head.readline().strip()
# in a branch => HEAD points to file containing last commit
if 'ref:' in extra:
# reference file path
ref_file = extra[5:]
branch_name = ref_file.rsplit('/', 1)[-1]

ref_file_path = os.path.abspath(os.path.join(gitdir, ref_file))
# check that we are in git folder
# (by stripping the git folder from the ref file path)
if os.path.relpath(
ref_file_path, gitdir).replace('\\', '/') != ref_file:
# out of git folder
extra = None
else:
# open the ref file
with io_open(ref_file_path, 'r') as fh_branch:
commit_hash = fh_branch.readline().strip()
extra = commit_hash[:8]
if branch_name != "master":
extra += '.' + branch_name

# detached HEAD mode, already have commit hash
else:
extra = extra[:8]

# Append commit hash (and branch) to version string if not tagged
if extra is not None:
try:
with io_open(os.path.join(gitdir, "refs", "tags",
'v' + __version__)) as fdv:
if fdv.readline().strip()[:8] != extra[:8]:
__version__ += '-' + extra
except Exception as e:
if "No such file" not in str(e):
raise
Binary file added tqdm/_version.pyc
Binary file not shown.
6 changes: 6 additions & 0 deletions tqdm/auto.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import warnings
from .std import TqdmExperimentalWarning
with warnings.catch_warnings():
warnings.simplefilter("ignore", category=TqdmExperimentalWarning)
from .autonotebook import tqdm, trange
__all__ = ["tqdm", "trange"]
18 changes: 18 additions & 0 deletions tqdm/autonotebook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import os

try:
from IPython import get_ipython
if 'IPKernelApp' not in get_ipython().config: # pragma: no cover
raise ImportError("console")
if 'VSCODE_PID' in os.environ: # pragma: no cover
raise ImportError("vscode")
except:
from .std import tqdm, trange
else: # pragma: no cover
from .notebook import tqdm, trange
from .std import TqdmExperimentalWarning
from warnings import warn
warn("Using `tqdm.autonotebook.tqdm` in notebook mode."
" Use `tqdm.tqdm` instead to force console mode"
" (e.g. in jupyter console)", TqdmExperimentalWarning, stacklevel=2)
__all__ = ["tqdm", "trange"]
Loading