update
Browse files11 unmodified lines12131415161718192021222324252627281 unmodified line3031323334353637383940414243444546474849505111 unmodified linesimageSizeShort = 256imageSizeCrop = 224normalizeMeanList = numpy.array([0.485, 0.456, 0.406], dtype=numpy.float32)normalizeStdList = numpy.array([0.229, 0.224, 0.225], dtype=numpy.float32)labelList = ["wired", "wireless"]onnxSession = onnxSessionBuild(f"{pathModel}onnx/pp-lcNet_x1_0_table_cls.onnx")def inference(imageRgb):imageHeight, imageWidth = imageRgb.shape[0:2]ratio = imageSizeShort / float(min(imageHeight, imageWidth))imageResized = cv2.resize(imageRgb, (int(round(imageWidth * ratio)), int(round(imageHeight * ratio))))resizedHeight, resizedWidth = imageResized.shape[0:2]1 unmodified linecropX = int(round((resizedWidth - imageSizeCrop) / 2))cropY = int(round((resizedHeight - imageSizeCrop) / 2))imageCrop = imageResized[cropY:cropY + imageSizeCrop, cropX:cropX + imageSizeCrop]tensor = imageCrop.astype(numpy.float32) / 255.0tensor = (tensor - normalizeMeanList) / normalizeStdListtensor = numpy.expand_dims(tensor.transpose((2, 0, 1)), axis=0).astype(numpy.float32)tensorOutputList = onnxSession.run(None, {"x": tensor})scoreList = tensorOutputList[0][0]index = int(numpy.argmax(scoreList))return {"label": labelList[index],"score": float(scoreList[index])}image = cv2.imread(sys.argv[1])11 unmodified lines1213141516171819202122232425262728291 unmodified line31323334353637383940414243444546474849505152535411 unmodified linesimageSizeShort = 256imageSizeCrop = 224meanList = numpy.array([0.485, 0.456, 0.406], dtype=numpy.float32)standardList = numpy.array([0.229, 0.224, 0.225], dtype=numpy.float32)labelList = ["wired", "wireless"]onnxSession = onnxSessionBuild(f"{pathModel}onnx/pp-lcNet_x1_0_table_cls.onnx")def imageResize(imageRgb):imageHeight, imageWidth = imageRgb.shape[0:2]ratio = imageSizeShort / float(min(imageHeight, imageWidth))imageResized = cv2.resize(imageRgb, (int(round(imageWidth * ratio)), int(round(imageHeight * ratio))))resizedHeight, resizedWidth = imageResized.shape[0:2]1 unmodified linecropX = int(round((resizedWidth - imageSizeCrop) / 2))cropY = int(round((resizedHeight - imageSizeCrop) / 2))return imageResized[cropY:cropY + imageSizeCrop, cropX:cropX + imageSizeCrop]def inference(imageRgb):imageCrop = imageResize(imageRgb)tensor = imageCrop.astype(numpy.float32) / 255.0tensor = (tensor - meanList) / standardListtensor = numpy.expand_dims(tensor.transpose((2, 0, 1)), axis=0).astype(numpy.float32)tensorOutputList = onnxSession.run(None, {"x": tensor})probabilityList = tensorOutputList[0][0]index = int(numpy.argmax(probabilityList))return {"label": labelList[index],"score": float(probabilityList[index])}image = cv2.imread(sys.argv[1])
PP-LCNet_x1_0_table_cls/src/example.py+12-9