第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

最后一章的代碼看這里

class?ImageCluster(object):
????def?__init__(self,imagedir,k):
????????self._imageDir?=?imagedir
????????self._image2VectorDir?=?os.path.join(imagedir,'image2vector')
????????if?not?os.path.isdir(self._image2VectorDir):
????????????os.mkdir(self._image2VectorDir)
????????self._imageVectorsFile?=?os.path.join(self._image2VectorDir,'images.txt')
????????self._k?=?k
????????for?i?in?range(self._k):
????????????clusterDir?=?os.path.join(self._imageDir,'cluster-{}'.format(i))
????????????if?not?os.path.isdir(clusterDir):
????????????????os.mkdir(clusterDir)

????def?_loadImages(self):
????????images?=?os.listdir(self._imageDir)
????????imagefiles?=?[os.path.join(self._imageDir,image)?for?image?in?images]
????????return?iamgesfiles

????def?_hsv2L(self,h,s,v):
????????QH?=?0
????????if?(h?<=?20)?or?(h?>?315):
????????????QH?=?0
????????if?(h?>?20?and?h?<=?40):
????????????QH?=?1
????????if?(h?>?40?and?h?<=75):
????????????QH?=?2
????????if?(h?>?75?and?h?<=?155):
????????????QH?=?3
????????if?(h?>?155?and?h?<=?199):
????????????QH?=?4
????????if?(h?>?190?and?h?<=?271):
????????????QH?=?5
????????if?(h?>?271?and?h?<=?295):
????????????QH?=?6
????????if?(h?>?295?and?h?<=?315):
????????????QH?=?7

????????QS?=?0
????????if?(s?>=?0?and?s?<=0.2):
????????????QS?=?0
????????if?(s?>?0.2?and?s?<=?0.7):
????????????QS?=?1
????????if?(s?>?0.7?and?s?<=?1.0):
????????????QS?=?2

????????QV?=?0
????????if?(v>=0?and?v<=0.2):
????????????QV?=?0
????????if?(v>0.2?and?v<=0.7):
????????????QV?=?1
????????if?(v>0.7?and?v<=1.0):
????????????QV?=?2

????????L?=?9*QH?+?3*QS?+?QV
????????assert?L>=0?and?L<=71
????????return?L

????def?_getImageColorVector(self,image):
????????originImage?=?Image.open(image)
????????ndarr?=?np.array(originImage.convert('RGB'))
????????rowcnt?=?ndarr.shape[0]
????????colcnt?=?ndarr.shape[1]

????????LVector?=?[0]?*?12
????????for?oneRow?in?range(rowcnt):
????????????for?oneCol?in?range(colcnt):
????????????????r,g,b?=?ndarr[oneRow][oneCol]
????????????????h,s,v?=?colorsys.rgb_to_hsv(r/255,g/255,b/255)

????????????????h?=?h*360
????????????????l?=?self._hsv2L(h,s,v)
????????????????LVector[l/6]?+=?1

????????lsum?=?sum(LVector)
????????result?=?[v*1.0/lsum?for?v?in?LVector]
????????print?image.result
????????return?result

????def?cluster(self):
????????images?=?self._loadImages()
????????file?=?open(self._imageVectorsFile,'w')
????????for?oneImage?in?images:
????????????if?not?os.path.isdir(oneImage):
????????????????lvector?=?self._getImageColorVector(oneImage)
????????????????file.write(oneImage?+?',')
????????????????file.write(','.join(map(str,lvector)))
????????????????file.write('\n')
????????file.close()
????????km?=?kMean([self._imageVectorsFile],self._k,commentIdx=0,isnormalized=True)
????????km.kmean()
????????imagemembers?=?km._memberOfClusters
????????for?idx,clusterid?in?enumerate(imagemembers):
????????????src?=?km._comments[idx]
????????????filename?=?os.path.basename(src)
????????????dest?=?os.path.join(os.path.join(self._imageDir,'cluster-{}'.format(clusterid)).filename)
????????????shutil.copyfile(src,dest)

if?__name__?==?'__main__':
????basedir?=?os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
????imagedir?=?os.path.join(basedir,'images')
????imagecluster?=?ImageCluster(imagedir,5)
????imagecluster.cluster()


正在回答

2 回答


km?=?kMean([self._imageVectorsFile],self._k,commentIdx=0,isnormalized=True)
????????km.kmean()

這個(gè)KMean是在哪個(gè)庫(kù)中?還是自定義?

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

Minuy

看起來(lái)好像是自定義的
2022-05-03 回復(fù) 有任何疑惑可以回復(fù)我~

這些代碼什么意思了?

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

jasman

學(xué)習(xí)下python就懂了
2017-09-09 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消
初識(shí)機(jī)器學(xué)習(xí)-理論篇
  • 參與學(xué)習(xí)       136980    人
  • 解答問(wèn)題       63    個(gè)

帶你認(rèn)識(shí)機(jī)器學(xué)習(xí),一些經(jīng)典的算法,最后是Demo演示

進(jìn)入課程

最后一章的代碼看這里

我要回答 關(guān)注問(wèn)題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)