基于内容的3D模型文件格式检测【3DFD】

3DFD是基于深度学习的3D模型文件格式检测开发包,支持DAE、FBX、GLB、GLTF、OBJ、PLY、STL等7种常见格式。官方下载地址:3DFD - 3D模型格式检测开发包 。

1、目录组织

3DFD开发包的目录组织说明如下:

3d_format_detector    
  | - model.pt                  # 检测器预训练模型
  | - detector.py               # 检测器实现类   
  | - demo.py                   # 检测器使用演示代码
  | - requirements.txt          # 依赖声明文件
  | - data                      # 示例3D模型文件目录
    | - 001.dae                 # dae测试文件 
    | - ...

2、快速上手

使用开发包提供的Detector类,可以快速检测指定磁盘文件或字节串(bytes)的格式分类。

2.1 检测磁盘文件

下面的代码实例化一个Detector类并检测指定的文件格式类别:

from detector import Detector

detector = Detector()
fns = [                                    # 要检测的目标文件列表
  'data/001.bin',  
  'data/002.bin', 
  'data/003.bin']
labels = detector.detect_files(fns)
print(labels)                              # 输出: ['stl', 'dae', 'fbx']

2.2 检测字节串

下面的代码实例化Detector类并检测指定字节串表示的3D模型格式:

from detector import Detector

buffer_to_detect = '''
# 3ds Max Wavefront OBJ Exporter v0.97b 

#
# object Cylinder001
#

v  9.2388 0.0000 3.8268
v  7.0711 0.0000 7.0711
v  3.8268 0.0000 9.2388
...
f 80/60/32 66/47/18 82/86/34 96/88/48
s 1
f 96/103/48 82/104/34 81/105/33 83/106/35 84/107/36 85/108/37 86/109/38 87/110/39 88/111/40 89/112/41 90/113/42 91/114/43 92/115/44 93/116/45 94/117/46 95/118/47
# 82 polygons
'''

detector = Detector()
labels = detector.detect_buffers([buffer_to_detect])
print(labels)                                   # 输出:[ 'obj' ]

3、使用GPU

默认情况下,Detector使用CPU进行推理,可以在实例化Detector时指定推理设备。

例如:

from detector import Detector

detector = Detector(device='cuda:0')            # 使用GPU
fns = ['data/001.dae', 'data/001.gltf']
labels = detector.detect_files(fns)

4、单样本检测API

当仅需要检测单个文件或单个字节串时,可以使用detect_file()detect_buffer(), 这两个API只是对应的批量检测API的简单语法糖封装。

例如使用 detect_file()检测单个文件:

from detector import Detector

detector = Detector()
label = detector.detect_file('data/001.stl')
print(label)                                     # 输出:'stl'

或者使用 detect_buffer()检测单个字节串:

from detector import Detector

buffer_to_detect = '''...'''

label = detector.detect_buffer(buffer_to_detect)
print(label)

原文链接:3DFD - 3D模型格式检测开发包 - 汇智网 

  • 5
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值