欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

pytorch 批次遍歷數(shù)據(jù)集打印數(shù)據(jù)的例子

 更新時(shí)間:2019年12月30日 10:12:58   作者:風(fēng)澤茹嵐  
今天小編就為大家分享一篇pytorch 批次遍歷數(shù)據(jù)集打印數(shù)據(jù)的例子,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來(lái)看看吧

我就廢話不多說了,直接上代碼吧!

from os import listdir
import os
from time import time
 
import torch.utils.data as data
import torchvision.transforms as transforms
from torch.utils.data import DataLoader
 
def printProgressBar(iteration, total, prefix='', suffix='', decimals=1, length=100,
           fill='=', empty=' ', tip='>', begin='[', end=']', done="[DONE]", clear=True):
  percent = ("{0:." + str(decimals) + "f}").format(100 * (iteration / float(total)))
  filledLength = int(length * iteration // total)
  bar = fill * filledLength
  if iteration != total:
    bar = bar + tip
  bar = bar + empty * (length - filledLength - len(tip))
  display = '\r{prefix}{begin}{bar}{end} {percent}%{suffix}' \
    .format(prefix=prefix, begin=begin, bar=bar, end=end, percent=percent, suffix=suffix)
  print(display, end=''), # comma after print() required for python 2
  if iteration == total: # print with newline on complete
    if clear: # display given complete message with spaces to 'erase' previous progress bar
      finish = '\r{prefix}{done}'.format(prefix=prefix, done=done)
      if hasattr(str, 'decode'): # handle python 2 non-unicode strings for proper length measure
        finish = finish.decode('utf-8')
        display = display.decode('utf-8')
      clear = ' ' * max(len(display) - len(finish), 0)
      print(finish + clear)
    else:
      print('')
 
 
class DatasetFromFolder(data.Dataset):
  def __init__(self, image_dir):
    super(DatasetFromFolder, self).__init__()
    self.photo_path = os.path.join(image_dir, "a")
    self.sketch_path = os.path.join(image_dir, "b")
    self.image_filenames = [x for x in listdir(self.photo_path) if is_image_file(x)]
 
    transform_list = [transforms.ToTensor(),
             transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))]
 
    self.transform = transforms.Compose(transform_list)
 
  def __getitem__(self, index):
    # Load Image
    input = load_img(os.path.join(self.photo_path, self.image_filenames[index]))
    input = self.transform(input)
    target = load_img(os.path.join(self.sketch_path, self.image_filenames[index]))
    target = self.transform(target)
 
    return input, target
 
  def __len__(self):
    return len(self.image_filenames)
 
if __name__ == '__main__':
  dataset = DatasetFromFolder("./dataset/facades/train")
  dataloader = DataLoader(dataset=dataset, num_workers=8, batch_size=1, shuffle=True)
  total = len(dataloader)
  for epoch in range(20):
    t0 = time()
    for i, batch in enumerate(dataloader):
      real_a, real_b = batch[0], batch[1]
      printProgressBar(i + 1, total + 1,
               length=20,
               prefix='Epoch %s ' % str(1),
               suffix=', d_loss: %d' % 1)
    printProgressBar(total, total,
             done='Epoch [%s] ' % str(epoch) +
               ', time: %.2f s' % (time() - t0)
             )

以上這篇pytorch 批次遍歷數(shù)據(jù)集打印數(shù)據(jù)的例子就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • OpenCV實(shí)現(xiàn)常見的四種圖像幾何變換

    OpenCV實(shí)現(xiàn)常見的四種圖像幾何變換

    這篇文章主要介紹了利用OpenCV實(shí)現(xiàn)的四種圖像幾何變換:縮放、翻轉(zhuǎn)、仿射變換及透視。文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編學(xué)習(xí)一下
    2022-04-04
  • Python列表(List)知識(shí)點(diǎn)總結(jié)

    Python列表(List)知識(shí)點(diǎn)總結(jié)

    在本篇文章中小編給大家分享了關(guān)于Python列表(List)知識(shí)點(diǎn)一直對(duì)應(yīng)的實(shí)例內(nèi)容,需要的朋友們學(xué)習(xí)下。
    2019-02-02
  • Python3 webservice接口測(cè)試代碼詳解

    Python3 webservice接口測(cè)試代碼詳解

    這篇文章主要介紹了Python3 webservice接口測(cè)試代碼詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-06-06
  • 在Python中繪制帶有連接線的雙餅圖(操作代碼)

    在Python中繪制帶有連接線的雙餅圖(操作代碼)

    這篇文章主要介紹了如何在Python中繪制帶有連接線的雙餅圖,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-05-05
  • python實(shí)現(xiàn)網(wǎng)上購(gòu)物系統(tǒng)

    python實(shí)現(xiàn)網(wǎng)上購(gòu)物系統(tǒng)

    這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)網(wǎng)上購(gòu)物系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-06-06
  • python3中TQDM庫(kù)安裝及使用詳解

    python3中TQDM庫(kù)安裝及使用詳解

    在本篇內(nèi)容里小編給大家整理了關(guān)于python3中TQDM庫(kù)安裝及使用的相關(guān)知識(shí)點(diǎn),有興趣的朋友們可以學(xué)習(xí)下。
    2020-11-11
  • 爬蟲框架 Feapder 和 Scrapy 的對(duì)比分析

    爬蟲框架 Feapder 和 Scrapy 的對(duì)比分析

    本篇文章在源碼層面比對(duì) feapder、scrapy 、scrapy-redis 的設(shè)計(jì),閱讀本文后,會(huì)加深您對(duì) scrapy 以及 feapder 的了解,以及為什么推薦使用 feapder,剛興趣的朋友可以參考下面文章內(nèi)容
    2021-09-09
  • Python XML模塊數(shù)據(jù)解析與生成利器的使用掌握

    Python XML模塊數(shù)據(jù)解析與生成利器的使用掌握

    這篇文章主要為大家介紹了Python XML模塊數(shù)據(jù)解析與生成利器的使用實(shí)例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2024-01-01
  • Python自動(dòng)提取項(xiàng)目中導(dǎo)入的庫(kù)及其版本信息

    Python自動(dòng)提取項(xiàng)目中導(dǎo)入的庫(kù)及其版本信息

    在我們有時(shí)需要遷移或部署項(xiàng)目時(shí),需要知道項(xiàng)目所依賴的三方包和版本,本文就來(lái)介紹一下Python自動(dòng)提取項(xiàng)目中導(dǎo)入的庫(kù)及其版本信息,具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-03-03
  • 基于python實(shí)現(xiàn)簡(jiǎn)單C/S模式代碼實(shí)例

    基于python實(shí)現(xiàn)簡(jiǎn)單C/S模式代碼實(shí)例

    這篇文章主要介紹了基于python實(shí)現(xiàn)簡(jiǎn)單C/S模式代碼實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-09-09

最新評(píng)論