deeplabcut使用

cuda11.2和cudnn8.1安装

  1. win
    最新的 Win11/WIN10 安装CUDA11.2和cuDNN
  2. linux
    ubuntu 16.04 安装 cuda11.2 和cudnn8.2.1

dlc安装

  1. 创建虚拟环境
    在这里插入图片描述
    tensorflow与cuda和cudnn版本对应关系

  2. 安装deeplabcut=2.2.3 tensorflow=2.11.0 wxPython=4.0.4
    pip install deeplabcut==2.2.3
    deeplabcut里面包含了tensorflow的不用再安装了

pip install tensorflow-gpu==2.12.0 -i https://pypi.tuna.tsinghua.edu.cn/simple/
pip install deeplabcut==2.2.3  -i https://pypi.tuna.tsinghua.edu.cn/simple/
pip install wxPython==4.0.4  -i https://pypi.tuna.tsinghua.edu.cn/simple/
-c https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
2023-03-08 22:26:34.816159: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2023-03-08 22:26:34.816852: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.

基本框架

在这里插入图片描述

本地操作(本地标注,服务器训练。gpu太low了)

官网教程

激活环境并进入ipython

在这里插入图片描述
linux系统有的用ipython不行就用python
在这里插入图片描述

导入deeplabcut

import deeplabcut 

在这里插入图片描述

创建文件

deeplabcut.create_new_project(r'project-name',r'Laborator',working_dirctory=[r'vidoes_path'],copy_videos=True)

在这里插入图片描述

配置文件

config.yaml

  1. bodyparts:
  2. numframes2pick
  3. skeleton:==注意字母不能写错了
config_path = 'G:\\new\\dlc\\dlc_mouse_4-cunyiyuan-2022-10-27\\config.yaml'

在这里插入图片描述

抽帧

deeplabcut.extract_frames(config)

错误
在这里插入图片描述
原因:配置文件中不能有中文
在这里插入图片描述

打标签

deeplabcut.label_frames(config_path)

在这里插入图片描述
在这里插入图片描述

检查标签

deeplabcut.check_labels(config_path)

在这里插入图片描述

服务器训练操作

import deeplabcut
config_path=‘’

Create a training dataset

deeplabcut.create_training_dataset(config_path, net_type='resnet_50', augmenter_type='imgaug')

Start training

deeplabcut.train_network(config_path, shuffle=1, trainingsetindex=0, gputouse=None, max_snapshots_to_keep=5, autotune=False, displayiters=100, saveiters=15000, maxiters=30000, allow_growth=True)

Evaluate the Trained Network

deeplabcut.evaluate_network(config_path,Shuffles=[1], plotting=True)

Video analysis

deeplabcut.analyze_videos(config_path, ['fullpath/analysis/project/videos'], videotype='avi', shuffle=1, trainingsetindex=0, gputouse='0', save_as_csv=True, destfolder=None, dynamic=(True, .5, 10))

filter

deeplabcut.filterpredictions(config_path,['fullpath/analysis/project/videos'], videotype='.mp4',filtertype= 'arima',ARdegree=5,MAdegree=2)

Plot Trajectories

deeplabcut.plot_trajectories(config_path, [‘fullpath/analysis/project/videos/reachingvideo1.avi’])

Create Labeled Videos

deeplabcut.create_labeled_video(config_path, videofile_path, videotype=VideoType, draw_skeleton=True, save_frames=True, trailpoints=0)

Extract “Skeleton” Features

deeplabcut.analyzeskeleton(config, video, videotype='avi', shuffle=1, trainingsetindex=0, save_as_csv=False, destfolder=None)

outlier

deeplabcut.extract_outlier_frames(config_path, ['videofile_path'], outlieralgorithm='manual')

refine

deeplabcut.refine_labels(config_path)
deeplabcut.merge_datasets(config_path)

恢复训练

deeplabcut源代码:
resume

  • 训练错误
    (0) DATA_LOSS: Unable to open table file /home/study11/szc/hw_01-szc-2023-03-07/dlc-models/iteration-0/hw_01Mar7-trainset80shuffle1/train/snapshot-100000.data-00000-of-00001: DATA_LOSS: not an sstable (bad magic number): perhaps your file is in a differ
#解决

四个权重文件,分别为:
1.checkpoint
2.snapshot-100.index
3.snapshot-100.meta
4.snapshot-100.data-00000-of-00001

那么导入时,init_weights应填"snapshot-100"的路径,
不是“snapshot-100.data-00000-of-00001”,也不是“snapshot”!
deeplabcut.train_network(config_path, shuffle=1, trainingsetindex=0, gputouse='0,1,2', max_snapshots_to_keep=10, autotune=False, displayiters=100, saveiters=10000, maxiters=200000, allow_growth=True)

3D操作

相机标定

  • 采集成对图片
    用get_paired_image.py采集标定的照片,复制到DLC创建的工程文件–标定文件夹里D:\Liqiqi\DeepLabCut_Liqiqi\liqiqi01-mouse-2022-12-12-3d\calibration_images】
  • 摄像头标定
    【(二)创建3D工程文件,注意:创建好新的工程文件之后,在标定的时候,config文件不需要改参数】
    工程文件创建成功后包括:calibration_images, camera_matrix, corners, and undistortion五个文件夹
  • calibration_images:该目录将包含从两台相机获取的一组校准图像。拍摄图像时:注意命名camera-1-01.jpg或者camera-2-01.jpg
  • camera_matrix:此目录将两台摄像机的参数存储为泡菜文件
  • corners:作为相机校准的一部分,在校准图像中检测到棋盘图案,这些图案将存储在此目录中
  • undistortion:为了检查校准,校准图像和相应的角点不会失真。这些未失真的图像被未失真的点覆盖,并将存储在此目录中。
  • 标定
    deeplabcut.calibrate_cameras(config_path3d, cbrow =8,cbcol =11,calibrate=False,alpha=0.9) # False是移除不好的照片
    deeplabcut.calibrate_cameras(config_path3d, cbrow =8,cbcol =11,calibrate=True,alpha=0.9) # Ture 是对好的照片进行标定

3d使用

官网教程

  1. create project
deeplabcut.create_new_project_3d('ProjectName','NameofLabeler',working_directory='path',num_cameras = 2)
  1. config_path3d
config_path3d = r'/content/drive/MyDrive/Colab Notebooks/39d/config.yaml'

deeplabcut.calibrate_cameras(config_path3d, cbrow =8,cbcol =11,calibrate=False,alpha=0.9) 

deeplabcut.calibrate_cameras(config_path3d, cbrow =8,cbcol =11,calibrate=True,alpha=0.9)

deeplabcut.check_undistortion(config_path3d, cbrow=8, cbcol=11)

deeplabcut.triangulate(config_path3d, r'videopath', filterpredictions=True, videotype='avi', save_as_csv=True, gputouse='0')

deeplabcut.create_labeled_video_3d(config_path3d, [r'/content/drive/MyDrive/Colab Notebooks/hw_01-szc-2023-03-07/videos'], start=200, end=600,videotype='mp4', xlim =[-50,50], ylim=[-30,30], zlim=[-30,30],view=[45,270])
  • 3
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
以下是Deeplabcut使用GPU的详细教程: 1. 安装CUDA和cuDNN 首先,需要安装CUDA和cuDNN。由于Deeplabcut需要在GPU上运行,因此需要安装CUDA和cuDNN,以便与GPU进行通信。安装步骤可以在NVIDIA官方网站找到。 2. 安装Deeplabcut 安装Deeplabcut使用以下命令: ``` pip install deeplabcut ``` 3. 配置GPU 在使用GPU之前,需要配置GPU。首先,需要检查GPU是否能够被Deeplabcut检测到。可以使用以下命令检查: ``` from tensorflow.python.client import device_lib print(device_lib.list_local_devices()) ``` 如果输出结果中包含GPU,则说明GPU已经被检测到。 接下来,需要配置GPU。可以使用以下代码: ``` import tensorflow as tf config = tf.ConfigProto() config.gpu_options.allow_growth = True session = tf.Session(config=config) ``` 这将允许TensorFlow在需要时动态分配GPU内存。 4. 运行Deeplabcut 现在,可以在GPU上运行Deeplabcut使用以下代码: ``` import deeplabcut deeplabcut.train_network('path/to/config.yaml', displayiters=100, saveiters=500) ``` 在这里,`displayiters`表示每隔多少次迭代显示一次训练进度,`saveiters`表示每隔多少次迭代保存一次模型。 5. 性能调优 如果需要进一步提高性能,可以使用以下代码: ``` import tensorflow as tf from keras.backend.tensorflow_backend import set_session config = tf.ConfigProto() config.gpu_options.allow_growth = True config.gpu_options.per_process_gpu_memory_fraction = 0.8 set_session(tf.Session(config=config)) ``` 这将限制TensorFlow使用的GPU内存的百分比。在这里,`0.8`表示使用80%的GPU内存。 以上是Deeplabcut GPU使用的详细教程。
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值