【问题标题】:transfering images into another data directory将图像传输到另一个数据目录
【发布时间】:2022-07-21 19:14:39
【问题描述】:

我的数据结构格式如下:

Dataset:
    training-
             -Cat
             -dog
             -monkey

我想将 10% 的文件从每个数据集传输/移动到验证数据集。我怎样才能使用python做到这一点?它也应该自动创建目录

Dataset:
    validation-
             -Cat
             -dog
             -monkey

【问题讨论】:

  • 你尝试了什么?

标签: python python-3.x


【解决方案1】:

你可以试试:

import os
source = 'C:/.../training/'
destination = 'C:/.../validation/'
 
if not os.path.exists(destination):
  # Create a new directory because it does not exist 
  os.makedirs(destination)

allfiles = os.listdir(source)
 
for f in allfiles:
    os.rename(source + f, destination + f)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-02-21
    • 1970-01-01
    • 1970-01-01
    • 2020-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多