我有下面的数据框形状(8683483),其中868是我的图像总数,3481是图像中的像素数。每一行代表一个特定的图像,图像编号在img
列中。我应用了无监督学习,并将这些图像聚集在cluster
列中。你知道吗
img cluster 0 1 2 3 4 5 6 7
0 3 1.0 1.0 1.0 1.0 1.0 1.0 1.0
1 2 1.0 1.0 1.0 1.0 1.0 1.0 1.0
2 3 1.0 1.0 1.0 1.0 1.0 1.0 1.0
3 1 1.0 1.0 1.0 1.0 1.0 1.0 1.0
5 3 1.0 1.0 1.0 1.0 1.0 1.0 1.0
6 3 1.0 1.0 1.0 1.0 1.0 1.0 1.0
8 3 1.0 1.0 1.0 1.0 1.0 1.0 1.0
9 3 1.0 1.0 1.0 1.0 1.0 1.0 1.0
10 2 1.0 1.0 1.0 1.0 1.0 1.0 1.0
11 2 1.0 1.0 1.0 1.0 1.0 1.0 1.0
13 3 1.0 1.0 1.0 1.0 1.0 1.0 1.0
15 1 1.0 1.0 1.0 1.0 1.0 1.0 1.0
我有一个文件夹,其中的图像标记与img
列相同。现在,我想根据这些图像所属的簇来分离它们。你知道吗
例如 图像“0,2,5,6,8,9,13”属于cluster3,因此我想将这些图像分离到名为“cluster3”的子文件夹中,cluster1和cluster2也是如此。你知道吗
有没有简单的方法?你知道吗
您可以基于python中的
os
(或者Dennis评论的shutil
模块移动文件,两者都可以工作)。据我所知,我们只关心img和cluster列dictionary = df.set_index("img")["cluster"].to_dict()
将返回一个字典,每个键是一个图像,每个簇是一个文件夹。 我不确定有多少个集群存在,但是我们也可以用os命令创建一些文件夹和子文件夹,如下所示然后,您可以将每个文件转到其相应的文件夹(我不确定每个文件的名称是什么,但现在我将假定名称是
img1.png, img2.png ...
等) 对于您的问题,我建议您重命名img列(或其他列,并将索引设置为下一行中的该列)这应该可以胜任。如果有任何错误,请告诉我
相关问题 更多 >
编程相关推荐