这东西真的是一个巨坑,好像在服务器上训练有时候会报这个错误,可以在报错的目录下(我的目录为:/MIP/.local/lib/python3.8/site-packages/nms)新建一个cpu_nms.py文件,加下如下代码:
import numpy as np def mymax(a, b): return a if a >= b else b def mymin(a, b): return a if a <= b else b def cpu_nms(dets, thresh): x1 = dets[:, 0] y1 = dets[:, 1] x2 = dets[:, 2] y2 = dets[:, 3] scores = dets[:, 4] areas = (x2 - x1 + 1) * (y2 - y1 + 1) order = scores.argsort()[::-1] ndets = dets.shape[0] suppressed = np.zeros((ndets), dtype=np.int) keep = [] for _i in range(ndets): i = order[_i] if suppressed[i] == 1: continue keep.append(i) ix1 = x1[i] iy1 = y1[i] ix2 = x2[i] iy2 = y2[i] iarea = areas[i] for _j in range(_i + 1, ndets): j = order[_j] if suppressed[i] == 1: continue xx1 = mymax(ix1, x1[j]) yy1 = mymax(iy1, y1[j]) xx2 = mymin(ix2, x2[j]) yy2 = mymin(iy2, y2[j]) w = mymax(0.0, xx2 - xx1 + 1) h = mymax(0.0, yy2 - yy1 + 1) inter = w * h ovr = inter / (iarea + areas[j] - inter) if ovr >= thresh: suppressed[j] = 1 return keep
这样可以解决No module named 'nms.cpu_nms'这个错误,但是我跑的代码在解决这个错误之后,又报了一个新的错误No module named 'nms.gpu_nms',在网上没有找到gpu_nms.py替换内容。
后来偶然发现,也许不一定是这个问题,但是我根据下面的方式解决了这个问题,下面是本人的代码目录,讲原程序的# from dataset.dataset_lits_val import Val_Dataset注释掉,改成下面这种形式,就不会报错了,个人感觉是文件的命名,dataset和utils与底层的源码命令一样引起的错误,请自辨,不一定对。



