日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python多图拼接并利用resnet提取特征

發布時間:2025/4/16 python 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python多图拼接并利用resnet提取特征 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

代碼功能:

1、將多張圖拼接成一張大圖;

2、基于resnet提取大圖的特征。

import torch import torch.nn as nn from torchvision import models, transforms from torch.autograd import Variable import numpy as np from PIL import Image from os import listdir #resnet50提取圖像特征 transform1 = transforms.Compose([transforms.Scale(256),transforms.CenterCrop(224),transforms.ToTensor()]) resnet50_feature_extractor = models.resnet50(pretrained = True) resnet50_feature_extractor.fc = nn.Linear(2048, 2048) torch.nn.init.eye(resnet50_feature_extractor.fc.weight) for param in resnet50_feature_extractor.parameters():param.requires_grad = Falseimages = [Image.open(fn) for fn in listdir() if fn.endswith('.png')] #多圖拼接成一張長圖 if len(images)>0:width,height=images[0].sizefor image in images:w,h = image.sizeif w>width:width=wif h>height: height=hlongImg = Image.new(images[0].mode,(width,height*len(images)))for i,im in enumerate(images):longImg.paste(im,box=(0,i*height))#拼接#長圖向量化 imgarr = np.array(longImg)if imgarr.shape[2] == 4: #四通道轉為三通道img1 = img.convert("RGB")#img = Image.fromarray(img.astype('uint8')).convert('RGB')img2 = transform1(img1)x = Variable(torch.unsqueeze(img2, dim=0).float(), requires_grad=False)y = resnet50_feature_extractor(x)y = y.data.numpy()print (y.shape)

?

總結

以上是生活随笔為你收集整理的python多图拼接并利用resnet提取特征的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。