本文整理匯總了Python中torch.utils.model_zoo.tqdm方法的典型用法代碼示例。如果您正苦於以下問題:Python model_zoo.tqdm方法的具體用法?Python model_zoo.tqdm怎麽用?Python model_zoo.tqdm使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類torch.utils.model_zoo
的用法示例。
在下文中一共展示了model_zoo.tqdm方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: stream_url
# 需要導入模塊: from torch.utils import model_zoo [as 別名]
# 或者: from torch.utils.model_zoo import tqdm [as 別名]
def stream_url(url: str,
start_byte: Optional[int] = None,
block_size: int = 32 * 1024,
progress_bar: bool = True) -> Iterable:
"""Stream url by chunk
Args:
url (str): Url.
start_byte (int, optional): Start streaming at that point (Default: ``None``).
block_size (int, optional): Size of chunks to stream (Default: ``32 * 1024``).
progress_bar (bool, optional): Display a progress bar (Default: ``True``).
"""
# If we already have the whole file, there is no need to download it again
req = urllib.request.Request(url, method="HEAD")
url_size = int(urllib.request.urlopen(req).info().get("Content-Length", -1))
if url_size == start_byte:
return
req = urllib.request.Request(url)
if start_byte:
req.headers["Range"] = "bytes={}-".format(start_byte)
with urllib.request.urlopen(req) as upointer, tqdm(
unit="B",
unit_scale=True,
unit_divisor=1024,
total=url_size,
disable=not progress_bar,
) as pbar:
num_bytes = 0
while True:
chunk = upointer.read(block_size)
if not chunk:
break
yield chunk
num_bytes += len(chunk)
pbar.update(len(chunk))
示例2: gen_bar_updater
# 需要導入模塊: from torch.utils import model_zoo [as 別名]
# 或者: from torch.utils.model_zoo import tqdm [as 別名]
def gen_bar_updater():
pbar = tqdm(total=None)
def bar_update(count, block_size, total_size):
if pbar.total is None and total_size:
pbar.total = total_size
progress_bytes = count * block_size
pbar.update(progress_bytes - pbar.n)
return bar_update
示例3: _save_response_content
# 需要導入模塊: from torch.utils import model_zoo [as 別名]
# 或者: from torch.utils.model_zoo import tqdm [as 別名]
def _save_response_content(response, destination, chunk_size=32768):
with open(destination, "wb") as f:
pbar = tqdm(total=None)
progress = 0
for chunk in response.iter_content(chunk_size):
if chunk: # filter out keep-alive new chunks
f.write(chunk)
progress += len(chunk)
pbar.update(progress - pbar.n)
pbar.close()
示例4: gen_bar_updater
# 需要導入模塊: from torch.utils import model_zoo [as 別名]
# 或者: from torch.utils.model_zoo import tqdm [as 別名]
def gen_bar_updater():
"""@TODO: Docs. Contribution is welcome."""
pbar = tqdm(total=None)
def bar_update(count, block_size, total_size):
if pbar.total is None and total_size:
pbar.total = total_size
progress_bytes = count * block_size
pbar.update(progress_bytes - pbar.n)
return bar_update