update
Browse files8 unmodified lines910111213141516171819207 unmodified lines282930313233343536373839407 unmodified lines484950515253545556573 unmodified lines61626364656667686970717273747576777815 unmodified lines9495969798991008 unmodified linespathModel = "./RT-DETR-L_wireless_table_cell_det/"imageSizeDetection = 640scoreThreshold = 0.3levelBoxNms = 0.5levelBoxContained = 0.9onnxSession = onnxSessionBuild(f"{pathModel}onnx/rt-detr-l_wireless_table_cell_det.onnx")7 unmodified linesy2 = min(coordinateFirstList[3], coordinateSecondList[3])if x2 <= x1 or y2 <= y1:return {"intersectionOverUnion": 0.0, "containment": 0.0}areaIntersection = (x2 - x1) * (y2 - y1)return {"intersectionOverUnion": areaIntersection / float(areaFirst + areaSecond - areaIntersection),"containment": areaIntersection / float(min(areaFirst, areaSecond))}def suppressionNonMaximum(itemList):7 unmodified linesfor b in range(len(resultList)):overlapObject = overlapCalculate(itemSortedList[a]["coordinate"], resultList[b]["coordinate"])isSameRegion = overlapObject["intersectionOverUnion"] >= levelBoxNmsisInside = overlapObject["containment"] >= levelBoxContainedif isSameRegion or isInside:isKeep = Falsebreak3 unmodified linesreturn resultListdef inference(imageRgb):resultList = []imageHeight, imageWidth = imageRgb.shape[0:2]imageResized = cv2.resize(imageRgb, (imageSizeDetection, imageSizeDetection), interpolation=cv2.INTER_CUBIC).astype(numpy.float32) / 255.0tensor = numpy.expand_dims(imageResized.transpose((2, 0, 1)), axis=0).astype(numpy.float32)tensorFeedObject = {"image": tensor,"im_shape": numpy.array([[imageSizeDetection, imageSizeDetection]], dtype=numpy.float32),"scale_factor": numpy.array([[imageSizeDetection / float(imageHeight), imageSizeDetection / float(imageWidth)]], dtype=numpy.float32)}tensorOutputList = onnxSession.run(None, tensorFeedObject)15 unmodified lines"coordinate": [x1, y1, x2, y2]})return suppressionNonMaximum(resultList)image = cv2.imread(sys.argv[1])imageRgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)8 unmodified lines910111213141516171819207 unmodified lines2829303132333435363738394041427 unmodified lines505152535455563 unmodified lines606162636465666768697071727374757677787980818283848586878889909192939495969715 unmodified lines1131141151161171181191201211228 unmodified linespathModel = "./RT-DETR-L_wireless_table_cell_det/"imageSizeModel = 640scoreThreshold = 0.3levelBoxNms = 0.5levelBoxContained = 0.9countContainedMinimum = 2onnxSession = onnxSessionBuild(f"{pathModel}onnx/rt-detr-l_wireless_table_cell_det.onnx")7 unmodified linesy2 = min(coordinateFirstList[3], coordinateSecondList[3])if x2 <= x1 or y2 <= y1:return {"intersectionOverUnion": 0.0, "containment": 0.0, "areaFirst": areaFirst, "areaSecond": areaSecond}areaIntersection = (x2 - x1) * (y2 - y1)return {"intersectionOverUnion": areaIntersection / float(areaFirst + areaSecond - areaIntersection),"containment": areaIntersection / float(min(areaFirst, areaSecond)),"areaFirst": areaFirst,"areaSecond": areaSecond}def suppressionNonMaximum(itemList):7 unmodified linesfor b in range(len(resultList)):overlapObject = overlapCalculate(itemSortedList[a]["coordinate"], resultList[b]["coordinate"])if overlapObject["intersectionOverUnion"] >= levelBoxNms:isKeep = Falsebreak3 unmodified linesreturn resultListdef suppressionContainer(itemList):resultList = []for a in range(len(itemList)):countContained = 0for b in range(len(itemList)):if a == b:continueoverlapObject = overlapCalculate(itemList[a]["coordinate"], itemList[b]["coordinate"])if overlapObject["containment"] >= levelBoxContained and overlapObject["areaFirst"] > overlapObject["areaSecond"]:countContained += 1if countContained < countContainedMinimum:resultList.append(itemList[a])return resultListdef inference(imageRgb):resultList = []imageHeight, imageWidth = imageRgb.shape[0:2]imageResized = cv2.resize(imageRgb, (imageSizeModel, imageSizeModel), interpolation=cv2.INTER_CUBIC).astype(numpy.float32) / 255.0tensor = numpy.expand_dims(imageResized.transpose((2, 0, 1)), axis=0).astype(numpy.float32)tensorFeedObject = {"image": tensor,"im_shape": numpy.array([[imageSizeModel, imageSizeModel]], dtype=numpy.float32),"scale_factor": numpy.array([[imageSizeModel / float(imageHeight), imageSizeModel / float(imageWidth)]], dtype=numpy.float32)}tensorOutputList = onnxSession.run(None, tensorFeedObject)15 unmodified lines"coordinate": [x1, y1, x2, y2]})resultList = suppressionNonMaximum(resultList)resultList = suppressionContainer(resultList)return resultListimage = cv2.imread(sys.argv[1])imageRgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
RT-DETR-L_wireless_table_cell_det/src/example.py+34-12