Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
2.0 kB
3
Indexable
Never
import os
root_folder = "/content/data/train/images"
list_image = os.listdir(root_folder)
with open("train.txt", "w") as f:
  for i in list_image:
    if "ipynb_checkpoints" in i:
      continue
    path_image = os.path.join(root_folder, i)
    f.write(path_image+"\n")
    

import os
root_folder = "/content/data/val/images"
list_image = os.listdir(root_folder)
with open("val.txt", "w") as f:
  for i in list_image:
    if "ipynb_checkpoints" in i:
      continue
    path_image = os.path.join(root_folder, i)
    f.write(path_image+"\n")

import os
root_file = "/content/data/valid/labels"
list_image = os.listdir(root_file)
for files in list_image:
    if files.split(".")[-1] == "txt":
        path_file = os.path.join(root_file, files)
        with open(path_file, "r") as f:
            content = f.readlines()
        with open(path_file, "w") as f:
            infor = "0"
            a = len(content)
            for i in content:
                for j in i.split()[1:]:
                    infor = infor + " " + str(j)
                if a ==1 :
                    f.write(infor)
                else:
                    f.write(infor+"\n")
                infor = "0"
                
import os
root_file = "/content/data/train/labels"
list_image = os.listdir(root_file)
for files in list_image:
    if files.split(".")[-1] == "txt":
        path_file = os.path.join(root_file, files)
        with open(path_file, "r") as f:
            content = f.readlines()
        with open(path_file, "w") as f:
            infor = "0"
            a = len(content)
            for i in content:
                for j in i.split()[1:]:
                    infor = infor + " " + str(j)
                if a ==1 :
                    f.write(infor)
                else:
                    f.write(infor+"\n")
                infor = "0"

!mv /content/data/train/labels/* /content/data/train/images/
!mv /content/data/valid/labels/* /content/data/valid/images/