目标检测OD

目标检测

目标检测开源实现(Yolo等框架)
Yolo:you only look once
1.环境安装
利用Anaconda安装pytorch和paddle深度学习环境+pycharm安装—免额外安装CUDA和cudnn(适合小白的保姆级教学)_didiaopao的博客-CSDN博客

conda create -n pytorch python=3.8

conda activate pytorch

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --set show_channel_urls yes

conda install pytorch torchvision torchaudio cpuonly -c pytorch

2.数据集标注
目标检测—利用labelimg制作自己的深度学习目标检测数据集_didiaopao的博客-CSDN博客

pip install labelimg -i https://pypi.tuna.tsinghua.edu.cn/simple

3.数据集格式
目标检测—数据集格式转化及训练集和验证集划分_didiaopao的博客-CSDN博客

VOC标签格式转yolo格式并划分训练集和测试集

4.训练自己的目标检测模型
目标检测—教你利用yolov5训练自己的目标检测模型_didiaopao的博

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
目标检测是计算机视觉领域的一个重要任务,它的目标是在图像或视频中准确地识别和定位特定对象。Python提供了许多强大的库和架来实现目标检测,其中最流行的是OpenCV和TensorFlow Object Detection API。 1. OpenCV:OpenCV是一个广泛使用的计算机视觉库,它提供了许多用于图像处理和分析的函数和工具。在OpenCV中,可以使用Haar级联分类器或基于特征的级联分类器(HOG)来进行目标检测。以下是一个使用OpenCV进行目标检测的示例代码: ```python import cv2 # 加载分类器 cascade_path = 'path/to/haarcascade_frontalface_default.xml' face_cascade = cv2.CascadeClassifier(cascade_path) # 加载图像 image_path = 'path/to/image.jpg' image = cv2.imread(image_path) # 转换为灰度图像 gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) # 目标检测 faces = face_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5, minSize=(30, 30)) # 绘制边界 for (x, y, w, h) in faces: cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 0), 2) # 显示结果 cv2.imshow('Detected Faces', image) cv2.waitKey(0) cv2.destroyAllWindows() ``` 2. TensorFlow Object Detection API:TensorFlow Object Detection API是一个基于TensorFlow的开源架,提供了训练和部署目标检测模型的工具和库。它支持多种目标检测算法,如Faster R-CNN、SSD和YOLO等。以下是一个使用TensorFlow Object Detection API进行目标检测的示例代码: ```python import tensorflow as tf from object_detection.utils import label_map_util from object_detection.utils import visualization_utils as vis_util import cv2 # 加载模型和标签映射 model_path = 'path/to/frozen_inference_graph.pb' label_map_path = 'path/to/label_map.pbtxt' num_classes = 90 detection_graph = tf.Graph() with detection_graph.as_default(): od_graph_def = tf.GraphDef() with tf.gfile.GFile(model_path, 'rb') as fid: serialized_graph = fid.read() od_graph_def.ParseFromString(serialized_graph) tf.import_graph_def(od_graph_def, name='') label_map = label_map_util.load_labelmap(label_map_path) categories = label_map_util.convert_label_map_to_categories(label_map, max_num_classes=num_classes, use_display_name=True) category_index = label_map_util.create_category_index(categories) # 加载图像 image_path = 'path/to/image.jpg' image = cv2.imread(image_path) image_expanded = np.expand_dims(image, axis=0) # 运行目标检测 with detection_graph.as_default(): with tf.Session(graph=detection_graph) as sess: # 获取输入和输出张量 image_tensor = detection_graph.get_tensor_by_name('image_tensor:0') boxes = detection_graph.get_tensor_by_name('detection_boxes:0') scores = detection_graph.get_tensor_by_name('detection_scores:0') classes = detection_graph.get_tensor_by_name('detection_classes:0') num_detections = detection_graph.get_tensor_by_name('num_detections:0') # 进行目标检测 (boxes, scores, classes, num_detections) = sess.run([boxes, scores, classes, num_detections], feed_dict={image_tensor: image_expanded}) # 可视化结果 vis_util.visualize_boxes_and_labels_on_image_array(image, np.squeeze(boxes), np.squeeze(classes).astype(np.int32), np.squeeze(scores), category_index, use_normalized_coordinates=True, line_thickness=8) # 显示结果 cv2.imshow('Detected Objects', image) cv2.waitKey(0) cv2.destroyAllWindows() ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值