Python?? ??? ?? ??, ???, ?? ? ??? ??
May 10, 2023 am 10:43 AM?? ?? ??, ???, ?? ? ???
??, ?? ??? ??? ?? ????? ????? ??? ??? 10?? ?????.
from PIL import Image
import torchvision.transforms as transforms
#使用PIL庫(kù)讀入圖片并進(jìn)行resize
def ResizeImage():
if not os.path.exists(rdir):
os.makedirs(rdir)
for i in range(10):
im = Image.open(dir+str(i)+".jpg")
im = im.resize((320,240),Image.BILINEAR) #第一個(gè)參數(shù)為想要的size,第二個(gè)參數(shù)為插值方法,雙線性插值這里用的是
im.save('{}/{}.jpg'.format(rdir, i))
?? 2: ???(?? ?? ??? ? ??? ??? ??)#圖像隨機(jī)剪裁和中心剪裁
def crop(lib):
for i in range(10):
img = Image.open(lib+"/"+str(i)+".jpg")
CenterCrop = transforms.CenterCrop((240,320)) #中心裁剪
cropped_image = CenterCrop(img) #PIL.Image.Image
# im=np.array(cropped_image) #可以將PIL.Image.Image轉(zhuǎn)成ndarry
#cropped_image.show() #將圖片顯示
cropped_image.save('{}/cen_crop{}.jpg'.format(rdir, i))
RandomCrop = transforms.RandomCrop(size=(240, 320)) #隨機(jī)剪裁
random_image = RandomCrop(img)
random_image.save('{}/rand_crop{}.jpg'.format(rdir, i))
?? 3: ??? ??#隨機(jī)旋轉(zhuǎn)
def random_rotation(lib):
for i in range(10):
img = Image.open(lib+"/"+str(i)+".jpg")
RR = transforms.RandomRotation(degrees=(10, 80)) #degrees為隨機(jī)旋轉(zhuǎn)的角度
rr_image = RR(img)
rr_image.save('{}/rand_rotation{}.jpg'.format(rdir, i))
?? 4: ???#圖片依概率翻轉(zhuǎn),p為翻轉(zhuǎn)的概率
def horizontal_flip(lib):
for i in range(10):
img = Image.open(lib+"/"+str(i)+".jpg")
HF = transforms.RandomHorizontalFlip(p=1.0) #p為概率,缺省時(shí)默認(rèn)0.5
hf_image = HF(img)
hf_image.save('{}/hori_flip{}.jpg'.format(rdir, i))
??? ?? ? ?????.
??? ??? ? ?? ?? ??, ??? ???, ???, ??? ??? ? ??? ??? ?????.
?? ??? ?? ?? - img.resize()??? ?? ?????. ??? ??? ????? ???? ??? jpg ?? png? ??? ? ????:#encoding=utf-8 #author: walker #date: 2014-05-15 #function: 更改圖片尺寸大小 from PIL import Image ''' filein: 輸入圖片 fileout: 輸出圖片 width: 輸出圖片寬度 height:輸出圖片高度 type:輸出圖片類型(png, gif, jpeg...) ''' def ResizeImage(filein, fileout, width, height, type): img = Image.open(filein) out = img.resize((width, height),Image.ANTIALIAS) #resize image with high-quality out.save(fileout, type) if __name__ == "__main__": filein = r'0.jpg' fileout = r'testout.png' width = 6000 height = 6000 type = 'png' ResizeImage(filein, fileout, width, height, type)? ?? img.resize((??, ??),Image.ANTIALIAS)
? ?? ????:
-
Image.NEAREST
: ?? ??Image.NEAREST
:低質(zhì)量 Image.BILINEAR
:雙線性Image.BICUBIC
:三次樣條插值Image.ANTIALIAS
Image.BILINEAR
: ???? Image.BICUBIC
: 3? ???? ?? ?????? ??Image.ANTIALIAS
: ??? ??????? ??? Python?? ??? ?? ??, ???, ?? ? ??? ??? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

??? ??











API ??? ??? ??? ?? ??? ???? ???? ???? ????. 1. Apikey? ?? ??? ?? ????, ????? ?? ?? ?? URL ?? ??? ?????. 2. Basicauth? ?? ???? ??? Base64 ??? ??? ??? ??? ????? ?????. 3. OAUTH2? ?? Client_ID ? Client_Secret? ?? ??? ?? ?? ?? ??? BearEtroken? ???????. 4. ?? ??? ???? ?? ?? ?? ???? ????? ???? ?? ?? ? ????. ???, ??? ?? ??? ??? ???? ?? ??? ???? ???? ?? ?????.

API? ?????? Python? ?? ?????? ???????. ??? ?????? ????, ??? ???, ??? ????, ?? ??? ???? ? ???? ????. ?? PipinstallRequests? ?? ?????? ??????. ?? ?? requests.get () ?? requests.post () ? ?? ???? ???? ?? ?? ?? ??? ?????. ?? ?? response.status_code ? response.json ()? ???? ?? ??? ???? ????? ??????. ?????, ?? ?? ?? ??? ???? ?? ?? ??? ???? ? ?? ?????? ???? ?? ???? ???? ???? ??????.

????? ?? ??? ?? ? ??? ?? ???? ?? ???? ?????. ?? ??? ???? ?? ??? ?? ?????. 1. ??? ???? ?? ?? ??? ?????. 2. ??? ?? ??? ??? ? ? ??? ?? ??? ? ???? ??? ???? ?????. 3. ?? ??? ?? ?? ??? ????? ? ?? ???? ???????. 4. ??? ?? ??? ?? ???? ?? ??? ??? ????. 5. ??? ??? ??? ? ???? ???????. ??? ??? unboundlocalerror ??? ?????. ??? ??? ???? ??? ????? ??? ??? ??? ???? ? ??????.

Python? ???? ????? ???? API? ???? Fastapi? ?????. ?? ??? ?? ????? ?????? ??? ??? ??? ???? ?? ? ? ????. Fastapi ? Asgi Server Uvicorn? ?? ? ? ????? ??? ??? ? ????. ??? ??, ?? ?? ?? ? ???? ?????? API? ???? ?? ? ? ????. Fastapi? ??? HTTP ??? ???? ?? ?? ? Swaggerui ? Redoc Documentation Systems? ?????. ?? ??? ?? URL ?? ??? ?? ? ??? ??, ?? ?? ??? ???? ???? ?? ?? ??? ??? ? ????. Pydantic ??? ???? ??? ?? ???? ???? ????? ? ??? ? ? ????.

????? ?? JSON ??? ????? ???? ??? ?????? 1. IJSON ?????? ???? ?? ? ?? ??? ?? ?????? ??? ????? ?????. 2. JSONLINES ???? ???? ?? JSON.LOADS ()? ?? ? ? ????. 3. ? ??? ?? ???? ?? ?? ??? ??????. ??? ??? ??? ?? ??? ????? ???? ?? ????? ?????.

??? ?? ? ? ??? ?? ?? ??? ???? ?? ?? ???? ??? ?? ??? ??? ? ????. ?? ?? ??? ??? ?? ?? ??? ???? ??? ???? ?? ???? ?? ?? ????. ?? ?? ?? ??? ?? ? ?? ?? ???? ?? ?? ??? ?? ?? ??? ??? ????. ??? ???? ?? ?? ?? ??? ???? ??? ??? ??? ??? ???? ?? ???? ???????.

?????, ??? ?? ??? ?? ??? ???? ????? ???? ??? ????, ??? ???? ??? ??, ?? ? ??? ???? ?? ?????. 1. For Loop? ???? ???? ???? ?? ? ??? ???? ???????. 2. enumerate ()? ???? ???? ?? ??? ?????. ?? ???? 0?? ?? ?? ??? ??? ? ????. 3. ?? ? ??? ???? ??? ? ? ???, ?? ?? ??? ?????????. ??? ??? ?? ?? ??? ? ???. ?? ??? ???? ???? ??? ??? ? ????. ?? ?? ?? \ _? ?? ??? ? ????. ??? ??? ?? ?????? ?? ??? ?? ??? ???? ?? ????.

Python? AIOHTTP? ?? ??? API ??? ?????. Async? ???? Coroutine ??? ???? Asyncio.run ????? ?? ??????. AIOHTTP? ?? ???? HTTP ??? ???? Asyncwith? ???? Clientsession? ???? ?? ??? ?????. asyncio.gather? ???? ?? ??? ??????. ?? ???? ??? ?????. ?? ?? ??, ??? ??? ???? ?? Jupyter? ??? ??? ??? ???????. ??? eventl
