【问题标题】:np.savetxt getting this (No such file or directory) Errornp.savetxt 得到这个(没有这样的文件或目录)错误
【发布时间】:2021-03-15 08:27:54
【问题描述】:

这是我的代码:

import numpy as np
import os
import json
import xmltodict

from xml.dom import minidom

BASE_Path = 'E:/Personal Projects/ML/computer_vision/open_image_vehicle/'


for file in os.listdir(os.path.join(BASE_Path,'cng_resized')):
    if file.endswith(".xml"):
        mydoc = minidom.parse(file)
        li = []
        ob = mydoc.getElementsByTagName('object')
        image_width = 416.0
        image_height = 416.0
        
        # total amount of items
        for i in ob:
            bbox = i.getElementsByTagName("bndbox")
            #print(len(bbox))
            for child in bbox:
                xmin = float(child.getElementsByTagName("xmin")[0].childNodes[0].nodeValue)
                ymin = float(child.getElementsByTagName("ymin")[0].childNodes[0].nodeValue)
                xmax = float(child.getElementsByTagName("xmax")[0].childNodes[0].nodeValue)
                ymax = float(child.getElementsByTagName("ymax")[0].childNodes[0].nodeValue)
                
                bbox_w =(xmax - xmin)/image_width
                bbox_h = (ymax - ymin)/image_height        
                x_center = (xmin + bbox_w/2)/image_width 
                y_center = (ymin + bbox_h/2)/image_height
                
                li.append([5,x_center,y_center,bbox_w,bbox_h])
                li  = np.array(li)
            
            print(BASE_Path)
            
            np.savetxt(os.path.join(BASE_Path, "/cng/labels/"+file.rsplit('.', 1)[0]+".txt"),
                       li,
                       fmt = ["%d", "%f", "%f", "%f", "%f"]
                       )
        
        

所需输出: E:/Personal Projects/ML/computer_vision/open_image_vehicle/cng/labels/cng.txt

但显示:没有这样的文件或目录:'E:/cng/labels/CNG.txt'

为什么 os.path.join 不加入 BASE_Path??

【问题讨论】:

    标签: python numpy file


    【解决方案1】:

    删除第一个 / 应该可以。所以替换为“cng/labels/”。否则,您正在复制,因为连接功能已经包含一个。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-31
      • 1970-01-01
      • 1970-01-01
      • 2013-08-08
      • 2013-11-04
      • 2012-02-18
      • 2012-10-21
      相关资源
      最近更新 更多