Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

get image from a folder based on order in python

I am clustering images stored in folder "/img" based on similarity. the output is given by:

resnet50_feature_list = []
path = "img2/"

for img_path in os.listdir(path):

input_path = os.path.join(path, img_path)    
img = image.load_img(input_path, target_size=(224, 224))
img_data = image.img_to_array(img)
img_data = np.expand_dims(img_data, axis=0)
img_data = preprocess_input(img_data)

resnet50_feature = model.predict(img_data)
resnet50_feature_np = np.array(resnet50_feature)
resnet50_feature_list.append(resnet50_feature_np.flatten())


resnet50_feature_list_np = np.array(resnet50_feature_list)   

and the labels look like this

 kmeans.labels_
 

array([0, 2, 2, 0, 0, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 0, 2, 2, 2, 2, 2, 1, 2, 1], dtype=int32)

I would like to inspect the clustering results but I am not sure how to do,

is there a way to collect all the images for a given cluster an store them in a folder named after the cluster?

alternatively how can I print all the images from a given cluster?

question from:https://stackoverflow.com/questions/65888979/get-image-from-a-folder-based-on-order-in-python

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...