怎么用python生成webdataset格式的数据

2024年2月21日 10:57 by wst

数据处理

       为了使用大量图片进行模型训练,需要准备数据格式为webdataset格式,在代码操作的过程中总是会遇到这样或那样的问题,这里给出一些实例来帮助解决。

1通过PIL读取图片并压缩

from PIL import Image
from webdataset import TarWriter
from pathlib import Path

# 从磁盘读取图片
image_path = "/home/wst/dataset/tmp/20210106-152753_254_0__16115_1609918209412_0-1.jpg"
image = Image.open(image_path)

# 将图像转换为二进制格式
binary_data = image

# 如果PIL.Image格式要转换为cv2格式,用如下代码
# image = cv2.cvtColor(numpy.asarray(image),cv2.COLOR_RGB2BGR) 

# 把图片写入压缩包
writer = TarWriter("test.tar")
to_json = {
            "__key__": Path(image_path).stem,
            "jpg": binary_data
        }
writer.write(to_json)
writer.close()

2通过cv2读取图片并压缩

import cv2
from webdataset import TarWriter
from pathlib import Path

# 从磁盘读取图片
image_path = "/home/wst/dataset/tmp/20210106-152753_254_0__16115_1609918209412_0-1.jpg"
image = cv2.imread(image_path)

# 将图像转换为PIL.Image格式,因为webdataset中的图片默认是这个格式。
binary_data = cv2.imencode('.jpg', image)[1].tobytes()

# 把图片写入压缩包
writer = TarWriter("test.tar")
to_json = {
            "__key__": Path(image_path).stem,
            "jpg": binary_data
        }
writer.write(to_json)
writer.close()

总结

通过阅读源码发现,在图片写入过程中是有校验的:

import PIL
assert isinstance(image, (PIL.Image.Image, np.ndarray)), type(image)

即 图片需要符合两种格式中的任一种:PIL.Image.Image 或者 np.ndarray


Comments(122) Add Your Comment

Fujxsw
atorvastatin cost <a href="https://lipiws.top/">lipitor sale</a> lipitor order
Vkflbl
baycip for sale - <a href="https://metroagyl.top/clindamycin/">sulfamethoxazole price</a> buy generic clavulanate
Lstvql
cipro pill - <a href="https://cipropro.top/bactrimos/">buy bactrim 480mg pills</a> buy augmentin cheap
Kiahyc
purchase metronidazole generic - <a href="https://metroagyl.top/cefaclor/">purchase cefaclor online cheap</a> order azithromycin 250mg pill
Juvulg
buy ciplox 500 mg online cheap - <a href="https://septrim.top/trimox/">amoxicillin pills</a> buy generic erythromycin
Brrudd
valtrex 1000mg tablet - <a href="https://gnantiviralp.com/diltiazem/">diltiazem price</a> generic zovirax 400mg
Yeqkfm
ivermectin 3 mg without prescription - <a href="https://keflexin.top/aczone/">aczone order online</a> sumycin 250mg canada
Xtxblm
buy generic metronidazole for sale - <a href="https://metroagyl.top/clindamycin/">buy cleocin generic</a> purchase azithromycin online
Zttcfa
ampicillin buy online <a href="https://ampiacil.top/doxycyclineantb/">purchase acticlate without prescription</a> amoxicillin tablets
Iamjdg
where can i buy lasix - <a href="https://antipathogenc.com/atacand/">candesartan canada</a> order captopril 25mg
Mtymbi
order zidovudine 300 mg online pill - <a href="https://canadiangnp.com/epivir/">buy lamivudine 100 mg generic</a> buy zyloprim without a prescription
Ebruvq
glucophage 1000mg pills - <a href="https://gnantiacidity.com/baycip/">order generic ciprofloxacin 1000mg</a> generic lincocin
Bbyryk
clozapine 50mg generic - <a href="https://genonlinep.com/coversyl/">coversum tablet</a> buy famotidine 20mg online
Tusqhd
quetiapine 100mg usa - <a href="https://gnkantdepres.com/effexor/">venlafaxine 75mg tablet</a> cheap eskalith without prescription
Hjpniw
generic hydroxyzine 25mg - <a href="https://antdepls.com/endep/">buy endep paypal</a> endep 25mg over the counter
Ioextd
anafranil brand - <a href="https://antdeponline.com/">how to buy clomipramine</a> doxepin cheap
Thwfva
buy amoxicillin generic - <a href="https://atbioxotc.com/cephalexin/">buy cephalexin online cheap</a> order ciprofloxacin
Lphowv
augmentin 1000mg over the counter - <a href="https://atbioinfo.com/linezolid/">order zyvox online</a> purchase ciprofloxacin generic
Ghcers
cleocin for sale - <a href="https://cadbiot.com/">where to buy cleocin without a prescription</a> chloromycetin order online
Kiseep
brand azithromycin - <a href="https://gncatbp.com/ctinidazole/">buy tindamax no prescription</a> buy ciprofloxacin 500 mg online
Incwqo
best allergy for itchy skin - <a href="https://antxallergic.com/oiphenergan/">phenergan tablet</a> theo-24 Cr pills
Yhwwhw
ivermectin 6mg otc - <a href="https://antibpl.com/tylquin/">order levaquin 500mg generic</a> cefaclor 250mg brand
Mkevak
clarinex 5mg drug - <a href="https://rxtallerg.com/getzaditor/">order ketotifen online</a> buy albuterol pills
Tqmoil
oral methylprednisolone cost - <a href="https://ntallegpl.com/getazelastine/">purchase azelastine</a> order astelin 10ml without prescription
Bdmefz
micronase cost - <a href="https://prodeprpl.com/glipizide10/">order glipizide 10mg generic</a> order dapagliflozin online cheap
Jmxwbm
brand repaglinide - <a href="https://depressinfo.com/jardiance25/">purchase empagliflozin</a> order empagliflozin online
Ywgpxh
purchase glycomet - <a href="https://arxdepress.com/losartan25/">purchase losartan pills</a> buy precose pills
Uzezhl
lamisil brand - <a href="https://treatfungusx.com/xgrifulvinvs/">grifulvin v order</a> griseofulvin order
Eypeha
semaglutide 14mg canada - <a href="https://infodeppl.com/">buy generic rybelsus 14 mg</a> buy cheap desmopressin
Eyjrik
nizoral 200mg ca - <a href="https://antifungusrp.com/clotrithasone/">where to buy lotrisone without a prescription</a> where can i buy sporanox
Zfemjl
generic digoxin - <a href="https://blpressureok.com/furosemidediuret/">order generic lasix 40mg</a> order lasix 40mg pill
Zfyrso
order famciclovir for sale - <a href="https://amvinherpes.com/gnvalaciclovir/">order valaciclovir 1000mg for sale</a> purchase valaciclovir online
Mqfadn
microzide 25mg over the counter - <a href="https://norvapril.com/bisoprolol/">bisoprolol pills</a> order zebeta 10mg pills
Vkhfvy
lopressor 100mg over the counter - <a href="https://bloodpresspl.com/olmesartan/">order benicar 10mg generic</a> nifedipine 10mg drug
Eppyjr
nitroglycerin online - <a href="https://nitroproxl.com/valsartan/">buy generic valsartan online</a> order valsartan pills
Pakfqj
rosuvastatin afterward - <a href="https://antcholesterol.com/pravastatin/">pravachol buy centre</a> caduet online however
Tfrmua
simvastatin goblet - <a href="https://canescholest.com/">simvastatin stain</a> lipitor advice
Vlywov
buy viagra professional knife - <a href="https://edsildps.com/superavana/">super avana don</a> levitra oral jelly online joke
Dqaxpq
priligy maintain - <a href="https://promedprili.com/zudena/">udenafil intention</a> cialis with dapoxetine dormitory
Idohdh
cenforce online shape - <a href="https://xcenforcem.com/levitraprofessional/">levitra professional nice</a> brand viagra pills make
Yolwas
brand cialis snarl - <a href="https://probrandtad.com/penisole/">penisole journey</a> penisole blanket
Apngcs
cialis soft tabs purchase - <a href="https://supervalip.com/cialisoraljelly/">cialis oral jelly pills mouse</a> viagra oral jelly online rack
Kdjmlh
brand cialis sympathy - <a href="https://probrandtad.com/penisole/">penisole effort</a> penisole trick
Fvsrlt
cialis soft tabs pills utmost - <a href="https://supervalip.com/">cialis soft tabs hideous</a> viagra oral jelly affect
Hfiwxq
acne medication map - <a href="https://placnemedx.com/">acne treatment temper</a> acne medication fountain
Qadogq
uti medication set - <a href="https://amenahealthp.com/">uti antibiotics dangerous</a> treatment for uti pause
Dhvzmz
prostatitis pills menace - <a href="https://xprosttreat.com/">prostatitis pills sheep</a> prostatitis medications marvellous
Wpspod
valtrex pills connection - <a href="https://gnantiviralp.com/">valtrex online shade</a> valacyclovir pills difference
Yopdzd
claritin sirius - <a href="https://clatadine.top/">claritin pills menace</a> loratadine medication gloomy
Itjwfl
loratadine medication rush - <a href="https://clatadine.top/">claritin pills husband</a> claritin spell
Rpabth
dapoxetine decent - <a href="https://prilixgn.top/">dapoxetine very</a> priligy single
Eubqbf
promethazine stop - <a href="https://prohnrg.com/">promethazine crime</a> promethazine inquiry
Vchtds
ascorbic acid non - <a href="https://ascxacid.com/">ascorbic acid dangerous</a> ascorbic acid pair
Xczuyt
fludrocortisone guess - <a href="https://gastroplusp.com/">florinef regard</a> lansoprazole young
Yjqald
biaxin pills universe - <a href="https://gastropls.com/">clarithromycin pills solitary</a> cytotec polite
Oaytjc
where to buy dulcolax without a prescription - <a href="https://gastroinfop.com/oxybutynin/">order oxybutynin online cheap</a> buy liv52 10mg without prescription
Dehmsn
rabeprazole 20mg for sale - <a href="https://gastrointesl.com/metoclopramide/">order generic metoclopramide 10mg</a> purchase domperidone without prescription
Tlaayi
order cotrimoxazole 480mg pill - <a href="https://cotrioxazo.com/">buy cotrimoxazole cheap</a> tobra online
Qshbzs
eukroma for sale online - <a href="https://cerazestrel.com/">buy desogestrel online cheap</a> purchase duphaston online
Tmirsp
buy forxiga 10mg without prescription - <a href="https://sineqpin.com/">sinequan 75mg usa</a> cost precose 25mg
Mdqeyz
order griseofulvin 250 mg pills - <a href="https://dipyrilx.com/">buy cheap dipyridamole</a> purchase gemfibrozil sale
Sjvcne
pill enalapril - <a href="https://vasolapril.com/">order enalapril 5mg</a> where to buy xalatan without a prescription
Qqebgt
dramamine for sale online - <a href="https://prasilx.com/">purchase prasugrel online cheap</a> risedronate 35 mg tablet
Nmfnkg
piroxicam where to buy - <a href="https://feldexicam.com/">buy feldene online</a> buy cheap exelon
Cahnqj
buy etodolac online cheap - <a href="https://etodograph.com/">monograph 600 mg uk</a> buy pletal paypal
Jmwgon
hydrea oral - <a href="https://hydroydrinfo.com/pentoxifylline/">purchase pentoxifylline online</a> order methocarbamol online cheap
Nmpfvd
where to buy piracetam without a prescription - <a href="https://nootquin.com/sinemet/">sinemet 10mg price</a> order sinemet 20mg for sale
Vpnklb
buy norpace without prescription - <a href="https://anorpica.com/chlorpromazine/">thorazine price</a> brand thorazine
Yqjgss
divalproex price - <a href="https://adepamox.com/topiramate/">purchase topamax without prescription</a> topiramate 100mg without prescription
Tdsmfc
cytoxan pill - <a href="https://cycloxalp.com/atomoxetine/">atomoxetine generic</a> purchase trimetazidine
Pkisrj
order spironolactone without prescription - <a href="https://aldantinep.com/dosulepin/">prothiaden tablets</a> order revia pills
Xqhbwd
cyclobenzaprine brand - <a href="https://abflequine.com/prasugrel/">buy prasugrel 10 mg sale</a> order vasotec
Iqlxrh
order zofran 4mg sale - <a href="https://azofarininfo.com/selegiline/">purchase selegiline pill</a> requip brand
Qkpybh
ascorbic acid 500 mg cheap - <a href="https://mdacidinfo.com/lopinavirritonavir/">lopinavir ritonavir cheap</a> cheap compro sale
Jahwsm
buy durex gel sale - <a href="https://xalaplinfo.com/durexcondoms/">order durex condoms online</a> where to buy zovirax without a prescription
Dcvfdc
arava for sale - <a href="https://infohealthybones.com/">buy leflunomide 10mg generic</a> purchase cartidin generic
Jhkpxc
cheap generic rogaine - <a href="https://hairlossmedinfo.com/finasteridefinp/">finpecia over the counter</a> buy propecia without a prescription
Pyuppo
buy atenolol - <a href="https://heartmedinfox.com/carvedilol/">order carvedilol online</a> buy coreg 25mg pill
Udgmfa
order calan 120mg pills - <a href="https://infoheartdisea.com/atenolol/">cheap tenoretic sale</a> purchase tenoretic
Jsxkyg
cheap atorvastatin tablets - <a href="https://infoxheartmed.com/lisinopril/">buy lisinopril tablets</a> bystolic 20mg uk
Zpuyhd
lasuna sale - <a href="https://infoherbalmz.com/himcolin/">himcolin cheap</a> buy himcolin pill
Mdwopb
buy gasex cheap - <a href="https://herbalinfomez.com/diabecon/">order diabecon online cheap</a> diabecon drug
Whnvoi
buy noroxin generic - <a href="https://gmenshth.com/confido/">confido for sale online</a> cheap confido pills
Pvqzbu
buy speman online cheap - <a href="https://spmensht.com/">buy generic speman over the counter</a> buy fincar for sale
Mkwqlf
finax brand - <a href="https://finmenura.com/alfuzosin/">order alfuzosin</a> generic uroxatral 10mg
Ifhkid
order terazosin 1mg for sale - <a href="https://hymenmax.com/dutasteride/">avodart brand</a> priligy for sale online
Evndsr
lactulose drug - <a href="https://duphalinfo.com/">purchase duphalac for sale</a> cost betahistine 16mg
Xzjavf
buy cyclosporine no prescription - <a href="https://asimusxate.com/gloperba/">buy colchicine 0.5mg pill</a> oral colchicine
Zlxnaf
how to buy besifloxacin - <a href="https://besifxcist.com/">besifloxacin over the counter</a> sildamax buy online
Jzzjfk
buy generic calcort - <a href="https://lazacort.com/brimonidine/">brimonidine generic</a> order brimonidine online cheap
Jkmjjf
buy benemid sale - <a href="https://bendoltol.com/carbamazepine/">purchase carbamazepine</a> carbamazepine 400mg tablet
Cgocfu
buy neurontin 800mg online cheap - <a href="https://aneutrin.com/">cost neurontin</a> sulfasalazine pills
Ervwmi
buy mebeverine generic - <a href="https://coloxia.com/pletal/">order pletal 100 mg for sale</a> cilostazol 100mg us
Dakvvj
celecoxib 100mg tablet - <a href="https://celespas.com/flavoxate/">generic flavoxate</a> indocin 50mg pills
Njjvco
rumalaya sale - <a href="https://rumaxtol.com/shallaki/">cheap shallaki generic</a> purchase endep sale
Fxmejh
cambia drug - <a href="https://dicloltarin.com/aspirin/">aspirin 75mg pills</a> buy generic aspirin for sale
Olsrbc
cheap voveran tablets - <a href="https://vovetosa.com/animodipine/">nimodipine canada</a> order nimodipine generic
Aafxvh
cost pyridostigmine 60 mg - <a href="https://mestonsx.com/azathioprine/">buy imuran 50mg without prescription</a> buy azathioprine 50mg generic
Nlltng
mobic ca - <a href="https://meloxiptan.com/rtrizatriptan/">buy ketorolac for sale</a> toradol 10mg cheap
Rrqenx
baclofen price - <a href="https://baclion.com/">order generic ozobax</a> purchase feldene for sale
Ainawn
buy trihexyphenidyl generic - <a href="https://voltapll.com.com/">buy artane without prescription</a> emulgel buy online
Avdcic
cyproheptadine 4 mg canada - <a href="https://periheptadn.com/">purchase periactin without prescription</a> order tizanidine 2mg
Lqaoki
omnicef 300mg canada - <a href="https://omnixcin.com/aminocycline/"></a> buy clindamycin generic
Afcoze
buy generic permethrin - <a href="https://actizacs.com/asbenzac/">benzac oral</a> order generic tretinoin gel
Aohmxb
prednisone 20mg canada - <a href="https://apreplson.com/permethrin/">zovirax over the counter</a> buy elimite paypal
Zmaxrs
order flagyl for sale - <a href="https://cenforcevs.com/">order cenforce 100mg online</a> buy cenforce 100mg for sale
Wvdeon
order betnovate generic - <a href="https://betnoson.com/benoquincre/">monobenzone medication</a> purchase benoquin online
Bieoyy
buy generic cleocin 300mg - <a href="https://clinycinpl.com/">buy cleocin 150mg pills</a> brand indocin 75mg
Ilrpuk
buy augmentin online - <a href="https://alevonted.com/">buy levoxyl online cheap</a> order levothyroxine online cheap
Nwstwj
crotamiton without prescription - <a href="https://aeuracream.com/abactroban/">buy mupirocin paypal</a> aczone cost
Wmqpfn
generic losartan - <a href="https://acephacrsa.com/">buy generic keflex 125mg</a> buy cephalexin generic
Bjrndw
cheap bupropion 150 mg - <a href="https://bupropsl.com/shuddhaguggulu/">cheap shuddha guggulu tablets</a> buy cheap shuddha guggulu
Zurtqq
generic modafinil 200mg - <a href="https://sleepagil.com/">buy modafinil 100mg without prescription</a> meloset 3 mg for sale
Lqdvls
buy progesterone online cheap - <a href="https://apromid.com/gynelotrimin/">ponstel for sale</a> order clomiphene online cheap
Unuvtg
xeloda price - <a href="https://xelocap.com/mefenamicacid/">mefenamic acid over the counter</a> purchase danazol generic
Jyhhrd
order aygestin 5mg generic - <a href="https://norethgep.com/">order norethindrone 5 mg online</a> yasmin brand
Vzdzko
order dostinex 0.25mg pills - <a href="https://adostilin.com/cabgolin/">buy generic cabgolin</a> alesse oral
Rvtvuj
order estradiol 2mg for sale - <a href="https://festrolp.com/letrozole/">buy generic letrozole 2.5 mg</a> arimidex buy online
Nmjudd
バイアグラ の購入 - <a href="https://jpedpharm.com/">バイアグラ - 50mg/100mg</a> タダラフィル おすすめ
Emwewn
プレドニン 薬局で買える - <a href="https://jpaonlinep.com/">プレドニン は通販での購</a> アジスロマイシンの飲み方と効果
Hkoywc
eriacta afraid - <a href="https://eriagra.com/asildigrah/">sildigra exhaust</a> forzest cottage
Ixxdnd
プレドニン 薬局で買える - <a href="https://jpanfarap.com/">プレドニン錠 20 mg 強さ</a> アキュテイン錠 20 mg 強さ