前提・実現したいこと
今まででは国旗の画像をクラスタリングするプログラムを用いて国旗のクラスタリングを行っていました。
実現したいことは顔画像をクラスタリングできるようにプログラムを改良したいです。
Pythonの付属モジュール(Jupyter notebook)を用いています。OSはWindows 10です
以下がソースコードです
Python
1import os 2import shutil 3import numpy as np 4from PIL import Image 5from skimage import data 6import pandas as pd 7from sklearn.cluster import KMeans 8 9 10for path in os.listdir('C:/Clustering2/human_origin'): 11 img=Image.open(f'C:/Clustering2/human_origin/{path}') 12 img=img.convert('RGB') 13 img_resize=img.resize((400,400)) 14 img_resize.save(f'C:/Clustering2/human_convert/{path}.jpg') 15 16 17feature=np.array([data.imread(f'C:/Clustering2/human_convert/{path}') for path in os.listdir('C:/Clustering2/human_convert')]) 18feature=feature.reshape(len(feature),-1).astype(np.float64) 19 20 21model=KMeans(n_clusters=15).fit(feature) 22 23 24labels=model.labels_ 25 26 27for label,path in zip(labels,os.listdir('C:/Clustering2/human_convert')): 28 os.makedirs(f"C:/Clustering2/human_group/{label}",exist_ok=True) 29 shutil.copyfile(f"C:/Clustering2/human_origin/{path.replace('.jpg','')}",f"C:/Clustering2/human_group/{label}/{path.replace('.jpg','')}") 30 print(label,path) 31 32``` 33```■■な機能を実装中に以下のエラーメッセージが発生しました。 34 35### 発生している問題・エラーメッセージ 36No such file or directory: 'C:/Clustering2/human_origin/img_136' 37``` 38 39 40 41### 試したこと 42 43エラー文をみて、画像が問題だと思い、画像を変えてみましたが改善されませんでした。 44 45追記(27/11/2018) 46国旗画像の場合では問題なく行えています。 47私の場合は顔画像をクラスタリングしたいのですが顔画像の場合だと上記エラーによりうまくいかなくなります。 48### 補足情報(FW/ツールのバージョンなど) 49Python(Jupyter notebook) 50使用ライブラリ 51scikit-learn 52 53K-Means法を用いたクラスタリングを行っています。
回答1件
あなたの回答
tips
プレビュー