This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| std::vector<cv::Mat> predictions; | |
| net.forward(predictions, net.getUnconnectedOutLayersNames()); | |
| const cv::Mat &output = predictions[0]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def unwrap_detection(input_image, output_data): | |
| class_ids = [] | |
| confidences = [] | |
| boxes = [] | |
| rows = output_data.shape[0] | |
| image_width, image_height, _ = input_image.shape | |
| x_factor = image_width / 640 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct Detection | |
| { | |
| int class_id; | |
| float confidence; | |
| cv::Rect box; | |
| }; | |
| void detect(const cv::Mat &input_image, constcv::Mat &output, std::vector<Detection> &output) { | |
| float x_factor = input_image.cols / 640.; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| indexes = cv2.dnn.NMSBoxes(boxes, confidences, 0.25, 0.45) | |
| result_class_ids = [] | |
| result_confidences = [] | |
| result_boxes = [] | |
| for i in indexes: | |
| result_confidences.append(confidences[i]) | |
| result_class_ids.append(class_ids[i]) | |
| result_boxes.append(boxes[i]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class_list = [] | |
| with open("classes.txt", "r") as f: | |
| class_list = [cname.strip() for cname in f.readlines()] | |
| colors = [(255, 255, 0), (0, 255, 0), (0, 255, 255), (255, 0, 0)] | |
| for i in range(len(result_class_ids)): | |
| box = result_boxes[i] | |
| class_id = result_class_ids[i] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # load the model as usual | |
| net = cv2.dnn.readNet('yolov5s.onnx') | |
| net.setPreferableBackend(cv2.dnn.DNN_BACKEND_CUDA) | |
| net.setPreferableTarget(cv2.dnn.DNN_TARGET_CUDA_FP16) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| auto net = cv::dnn::readNet("yolov5s.onnx"); | |
| net.setPreferableBackend(cv::dnn::DNN_BACKEND_CUDA); | |
| net.setPreferableTarget(cv::dnn::DNN_TARGET_CUDA_FP16); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import cv2 | |
| image_path = 'data/full/with_mask (4)' | |
| image = cv2.imread(image_path + '.jpg') | |
| class_list = ['using mask', 'without mask'] | |
| colors = [(0, 255, 0), (0, 255, 255)] | |
| height, width, _ = image.shape |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os, shutil, random | |
| # preparing the folder structure | |
| full_data_path = 'data/obj/' | |
| extension_allowed = '.jpg' | |
| split_percentage = 90 | |
| images_path = 'data/images/' | |
| if os.path.exists(images_path): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const N = 91; | |
| // generating a sequence 91 elements from 0 to 2π | |
| const xs = [...Array(N).keys()].map(x => 2*Math.PI*x / (N - 1)); | |
| // generating f(x) = sin(x) | |
| const signal = xs.map(x => Math.sin(x)); | |
| // sampling 20 random elements and adding a N(0, 0.4) gaussian error | |
| const sampleSize = 20; | |
| const sample = [...Array(N).keys()].sort(() => 0.5 - jStat.uniform.sample(0, 1)).slice(0, sampleSize).map(index => ({x: index, y: signal[index] + jStat.normal.sample(0.0, 0.4)})); |