《超过75w例医疗数据的猫狗皮肤病医疗数据集》AI模型训练
di:03
– 超过 10,000 只宠物
– 7 种宠物疾病和 4 种猫皮肤病的图像
– 超过 500,000 张宠物(狗和猫)图片
– 超过 250,000 张疾病图像
可用于AI模型训练
猫狗皮肤病医疗数据集
图像数量:
通常情况下,研究人员可以通过官方提供的链接或相关机构网站下载该数据集。请注意,使用时应遵循相应的许可协议和引用要求。
关键代码示例假设我们已经有了数据集的下载链接,可以使用 Python 的 requests 库来下载数据集:
import requests
import os
# 定义下载链接和保存路径
url = 'http://example.com/path/to/pet_dermatology_dataset.zip' # 替换为实际的下载链接
save_path = './pet_dermatology_dataset.zip'
# 检查是否已经下载过
if not os.path.exists(save_path):
print("Downloading dataset...")
response = requests.get(url, stream=True)
with open(save_path, 'wb') as f:
for chunk in response.iter_content(chunk_size=8192):
if chunk:
f.write(chunk)
print("Download complete.")
else:
print("Dataset already exists.")
# 解压数据集
import zipfile
with zipfile.ZipFile(save_path, 'r') as zip_ref:
zip_ref.extractall('./pet_dermatology_dataset')
2. 加载和显示图像及其标注以下是一个加载和显示图像及其标注框的示例:
import matplotlib.pyplot as plt
import numpy as np
from PIL import Image
import xml.etree.ElementTree as ET
def load_image_and_annotations(image_path, annotation_path):
image = Image.open(image_path).convert("RGB")
tree = ET.parse(annotation_path)
root = tree.getroot()
annotations = []
for obj in root.findall('object'):
name = obj.find('name').text
bbox = obj.find('bndbox')
xmin = int(bbox.find('xmin').text)
ymin = int(bbox.find('ymin').text)
xmax = int(bbox.find('xmax').text)
ymax = int(bbox.find('ymax').text)
annotations.append((name, (xmin, ymin, xmax, ymax)))
return image, annotations
def display_image_with_annotations(image, annotations):
fig, ax = plt.subplots(1, figsize=(10, 10))
ax.imshow(image)
for name, (xmin, ymin, xmax, ymax) in annotations:
rect = plt.Rectangle((xmin, ymin), xmax - xmin, ymax - ymin, fill=False, edgecolor='red', linewidth=2)
ax.add_patch(rect)
ax.text(xmin, ymin, name, fontsize=12, color='white', bbox=dict(facecolor='red', alpha=0.5))
plt.axis('off')
plt.show()
# 示例路径
image_path = './pet_dermatology_dataset/images/image_0001.jpg'
annotation_path = './pet_dermatology_dataset/annotations/image_0001.xml'
image, annotations = load_image_and_annotations(image_path, annotation_path)
display_image_with_annotations(image, annotations)
3. 创建 YOLO 格式的数据集YOLO 模型需要特定格式的数据集,通常包括图像文件和对应的标注文件(.txt 格式)。以下是一个将 XML 标注转换为 YOLO 格式的示例:
import os
import xml.etree.ElementTree as ET
def convert_to_yolo_format(xml_dir, img_dir, yolo_dir, classes):
os.makedirs(yolo_dir, exist_ok=True)
for xml_file in os.listdir(xml_dir):
if not xml_file.endswith('.xml'):
continue
tree = ET.parse(os.path.join(xml_dir, xml_file))
root = tree.getroot()
image_name = root.find('filename').text
image_path = os.path.join(img_dir, image_name)
image = Image.open(image_path)
width, height = image.size
yolo_file = os.path.splitext(xml_file)[0] + '.txt'
yolo_path = os.path.join(yolo_dir, yolo_file)
with open(yolo_path, 'w') as f:
for obj in root.findall('object'):
name = obj.find('name').text
class_id = classes.index(name)
bbox = obj.find('bndbox')
xmin = int(bbox.find('xmin').text)
ymin = int(bbox.find('ymin').text)
xmax = int(bbox.find('xmax').text)
ymax = int(bbox.find('ymax').text)
x_center = (xmin + xmax) / 2.0 / width
y_center = (ymin + ymax) / 2.0 / height
box_width = (xmax - xmin) / width
box_height = (ymax - ymin) / height
f.write(f"{class_id} {x_center} {y_center} {box_width} {box_height}n")
# 定义类名
classes = ['disease_A', 'disease_B', 'disease_C', 'disease_D', 'disease_E', 'disease_F', 'disease_G',
'cat_skin_disease_1', 'cat_skin_disease_2', 'cat_skin_disease_3', 'cat_skin_disease_4']
# 转换标注文件
convert_to_yolo_format(
xml_dir='./pet_dermatology_dataset/annotations',
img_dir='./pet_dermatology_dataset/images',
yolo_dir='./pet_dermatology_dataset/yolo_annotations',
classes=classes
)
4. 使用 YOLOv5 进行目标检测以下是一个使用 YOLOv5 进行目标检测的简单示例:
安装 YOLOv5:
git clone https://github.com/ultralytics/yolov5
cd yolov5
pip install -r requirements.txt
准备配置文件: 在 yolov5/data 目录下创建一个配置文件 pet_dermatology.yaml,内容如下:
train: ./pet_dermatology_dataset/images/train
val: ./pet_dermatology_dataset/images/val
nc: 11
names: ['disease_A', 'disease_B', 'disease_C', 'disease_D', 'disease_E', 'disease_F', 'disease_G',
'cat_skin_disease_1', 'cat_skin_disease_2', 'cat_skin_disease_3', 'cat_skin_disease_4']
划分数据集: 将数据集划分为训练集和验证集(例如,80% 训练集,20% 验证集)。
训练模型:
python train.py --img 640 --batch 16 --epochs 50 --data pet_dermatology.yaml --weights yolov5s.pt
评估模型:
python val.py --img 640 --batch 16 --data pet_dermatology.yaml --weights runs/train/exp/weights/best.pt
推理和可视化:
from yolov5 import detect
model = torch.hub.load('ultralytics/yolov5', 'custom', path='runs/train/exp/weights/best.pt')
results = model(image_path)
results.show()
通过上述步骤,您将拥有一个完整的猫狗皮肤病识别系统,包括数据集、预训练模型和相关的训练流程。希望这些代码能帮助您更好地利用该数据集!
相关知识
宠物皮肤病的流行病学数据分析
数据集下载地址(转)以下内容转自https://baijiahao.baidu.com/s?id=1615853849218131902&wfr=spider&for=pc
基于深度学习的犬种识别系统详解(网页版+YOLOv8/v7/v6/v5代码+训练数据集)
宠物医疗太贵?首个猫狗脸AI识别宠物医疗保险上架陆金所
猫狗图片分类 03分析图片数据
AI 数据集最常见的6大问题(附解决方案)
深度学习数据集
实战YOLOv8:从COCO到自定义数据集的训练全攻略
Pytorch采用AlexNet实现猫狗数据集分类(训练与预测)
宠物医生诊疗室 猫狗常见疾病一本通 宠物医疗 猫狗健康管理常见疾病防治 传染病皮肤病呼吸道疾病内分泌疾病 广东科技
网址: 猫狗皮肤病医疗数据集《75w例医疗数据的猫狗皮肤病医疗数据集》AI模型训练di:03– 超过 10,000 只宠物– 7 种宠物疾病和 4 种猫皮肤病的图像–超过 500,000 张宠物试用3000张 https://m.mcbbbk.com/newsview385887.html
上一篇: 什么是敏感性皮肤 |
下一篇: 敏感性皮肤的原因与护理指导 |