數(shù)據(jù)標記和模型訓練一直被認為是團隊在構建 AI 或機器學習基礎設施時所面臨的最大挑戰(zhàn)。兩者都是機器學習應用開發(fā)過程中的重要步驟,如果執(zhí)行不當就會導致結果不準確和性能下降。
數(shù)據(jù)標記對于所有形式的監(jiān)督學習來說都是必不可少的。在監(jiān)督學習中,整個數(shù)據(jù)集會被完全標記。同時,數(shù)據(jù)標記也是半監(jiān)督學習的一個關鍵步驟。在半監(jiān)督學習中,需要將較小的標記數(shù)據(jù)集與以編程方式自動標記其余數(shù)據(jù)集的算法相結合。對于最先進、最發(fā)達的機器學習領域之一的計算機視覺來說,標記至關重要。盡管數(shù)據(jù)標記十分重要,標記速度卻因為需要調節(jié)分散的人力團隊而十分緩慢。
與標記一樣,模型訓練是機器學習的另一個主要瓶頸。由于需要等待機器完成復雜的計算,訓練速度很慢。它要求團隊必須了解網(wǎng)絡、分布式系統(tǒng)、存儲、專用處理器(GPU 或 TPU)和云管理系統(tǒng)(Kubernetes 和 Docker)。
應用 NVIDIA TAO Toolkit 的
Superb AI Suite
Superb AI 為計算機視覺團隊帶來了一種既可以提供高質量訓練數(shù)據(jù)集,同時又能大幅減少所需時間的途徑。團隊可以在大部分數(shù)據(jù)準備流程中使用 Superb AI Suite 來實現(xiàn)更加節(jié)省時間和成本的流程,不再依賴人工標記員。

圖 1. Superb AI Suite提供覆蓋
整個數(shù)據(jù)生命周期的產(chǎn)品和服務
NVIDIA TAO Toolkit建立在 TensorFlow 和 PyTorch上,是 TAO 框架的低代碼版本,能夠以抽象化的方式降低框架的復雜性,加快模型的開發(fā)流程。TAO Toolkit 使用戶能夠借助強大的遷移學習,使用自己的數(shù)據(jù)對 NVIDIA 預先訓練的模型進行微調,并對推理進行優(yōu)化。

圖 2. NVIDIA TAO Toolkit 4.0 一覽
計算機視覺工程師可以結合使用 Superb AI Suite 和 TAO Toolkit 解決數(shù)據(jù)標記和模型訓練的難題。具體就是在套件中快速生成標記的數(shù)據(jù),并使用 TAO 訓練模型來執(zhí)行分類、檢測、分割等特定的計算機視覺任務。
計算機視覺數(shù)據(jù)集的準備
接下來將為您演示如何使用 Superb AI Suite 準備一個兼容 TAO Toolkit 的高質量計算機視覺數(shù)據(jù)集。我們將介紹如何下載數(shù)據(jù)集、在 Suite 上創(chuàng)建新項目、通過 Suite SDK 將數(shù)據(jù)上傳到項目中、使用 Superb AI 的自動標記功能快速標記數(shù)據(jù)集、導出已標記的數(shù)據(jù)集,以及設置 TAO Toolkit 配置以使用這些數(shù)據(jù)。
第 1 步:從使用 Suite SDK 開始
首先,在superb-ai.com 創(chuàng)建一個帳戶,然后按照快速入門指南安裝并驗證 Suite CLI。您應該能夠安裝最新版本的 spb-cli,并獲取用于身份驗證的 Suite 賬戶名/ 訪問密鑰。
第 2 步:下載數(shù)據(jù)集
本教程使用的是 COCO 數(shù)據(jù)集。這個大型對象檢測、分割和字幕數(shù)據(jù)集在計算機視覺研究界深受歡迎。
您可以使用此鏈接中的代碼片段下載該數(shù)據(jù)集 (https://github.com/Superb-AI-Suite/spb-example/blob/main/create-coco-project/download-coco.sh)。將其保存在一個名為 download-coco.sh 的文件中,并從終端運行 bash download-coco.sh,創(chuàng)建一個存儲 COCO 數(shù)據(jù)集的 data/ 目錄。
下一步是將 COCO 轉換成 Suite SDK 格式,以便對 COCO validation 2017 數(shù)據(jù)集中的五個最頻繁使用的數(shù)據(jù)類別進行采樣。本教程只處理邊界框注釋,但 Suite 也可以處理多邊形和關鍵點。
您可以使用此鏈接中的代碼片段執(zhí)行轉換 (https://github.com/Superb-AI-Suite/spb-example/blob/main/create-coco-project/convert.py)。將其保存在一個名為 convert.py 的文件中,并從終端運行 python convert.py。這將創(chuàng)建一個用于存儲圖像名稱和注釋信息的 upload-info.json 文件。
第 3 步:在 Suite SDK 中創(chuàng)建一個項目
通過 Suite SDK 創(chuàng)建項目的功能目前仍在開發(fā)中。在本次教學中,我們根據(jù) Superb AI 項目創(chuàng)建指南在網(wǎng)絡上創(chuàng)建一個項目。請按照下圖進行設置:

圖 3. Superb AI 項目創(chuàng)建菜單
-
選擇圖像數(shù)據(jù)類型
-
將項目名稱設置為 CocoTest
-
注釋類型選擇“邊界框”
-
創(chuàng)建五個匹配 COCO 類名稱的對象類:['person'、'car'、'chair'、'book'、'bottle']

圖 4. 在創(chuàng)建流程的這一步選擇和定義項目的對象類
如圖 5 所示,完成該流程后,您可以查看項目的主頁面。

圖 5. Superb AI Suite 項目主頁面
第 4 步:使用 Suite SDK 上傳數(shù)據(jù)
在創(chuàng)建完項目后,就可以開始上傳數(shù)據(jù)了。您可以使用此鏈接中的代碼片段上傳數(shù)據(jù) (https://github.com/Superb-AI-Suite/spb-example/blob/main/create-coco-project/upload.py)。將其保存在一個名為 upload.py 的文件中,然后在終端運行 python upload.py --project CocoTest --dataset coco-dataset。
這表示 CocoTest 是項目名稱,coco-dataset 是數(shù)據(jù)集名稱。然后將啟動上傳流程,可能需要幾個小時才能完成上傳,具體時間取決于設備的處理能力。
如圖 6 所示,您可以在 Suite 網(wǎng)頁上實時檢查上傳的數(shù)據(jù)集。

圖 6. 通過 Suite 列表視圖實時監(jiān)控上傳的數(shù)據(jù)集
第 5 步:標記數(shù)據(jù)集
下一步是標記 COCO 數(shù)據(jù)集。為了快速完成這項工作,請使用 Suite 強大的自動標記功能。具體來講就是 Auto-Label 和 Custom Auto-Label 這兩個強大的工具,會通過自動檢測對象并進行標記來提高標記效率。
Auto-Label 是一個由 Superb AI 開發(fā)的預訓練模型,可檢測和標記 100 多個常見對象;Custom Auto-Label 是一個使用您自己的數(shù)據(jù)訓練的模型,可檢測和標記小眾對象。
本教程中的 COCO 數(shù)據(jù)由五個能夠被 Auto-Label 標記的常見對象組成。請按照鏈接中的指南設置 Auto-Label(https://docs.superb-ai.com/docs/image)。請注意,應選擇 MSCO Box CAL 作為 Auto-Label 的 AI,并將對象名稱與各自應用的對象進行映射。處理 COCO 數(shù)據(jù)集中的所有 3283 個標簽可能需要大約一個小時。

圖 7. 創(chuàng)建完畢的 Auto-Label中的對象類設置
Auto-Label 運行完畢后,您會看到每個自動標記任務的難度:紅色代表困難,黃色代表中等,綠色代表容易。難度越高,自動標記對圖像進行錯誤標記的可能性就越大。
這種難度,或者說所估測的不確定性是根據(jù)對象尺寸的大小、照明條件的優(yōu)劣、場景的復雜度等因素計算出來的。在實際使用時,您可以很容易地按照難度對標簽進行分類和篩選,以便優(yōu)先處理出錯幾率較高的標簽。
第 6 步:從 Suite 中導出標記的數(shù)據(jù)集
在獲得標記的數(shù)據(jù)集后,導出并下載標簽。標簽內容不僅僅是注釋信息。為了充分利用一個標簽來訓練機器學習模型,您還必須知道其他信息,比如項目配置和關于原始數(shù)據(jù)的元信息。要想連同注釋文件一起下載所有這些信息,首先要請求導出,以便 Suite 系統(tǒng)可以創(chuàng)建一個供下載的壓縮文件。按照指南,從 Suite 中導出并下載標簽 (https://docs.superb-ai.com/docs/export-and-download-labels)。

圖 8. 通過用戶界面導出數(shù)據(jù)集
在導出標簽時,將創(chuàng)建一個壓縮好的 zip 文件供您下載。導出結果文件夾將包含關于整個項目的基本信息、每個標簽的注釋信息以及每個數(shù)據(jù)資產(chǎn)的元數(shù)據(jù)。更多細節(jié)請參見導出結果格式文件 (https://docs.superb-ai.com/docs/export-result-format)。
第 7 步:將輸出結果轉換成 COCO 格式
接下來,創(chuàng)建一個腳本,將您的標簽數(shù)據(jù)轉換成可以輸入到 TAO Toolkit 的格式,比如 COCO 格式。請注意,因為本教程使用的是 COCO 數(shù)據(jù)集,所以數(shù)據(jù)已經(jīng)是 COCO 格式了。例如,您可以在下面找到一個隨機導出標簽的 JSON 文件:
{
"objects": [
{
"id": "7e9fe8ee-50c7-4d4f-9e2c-145d894a8a26",
"class_id": "7b8205ef-b251-450c-b628-e6b9cac1a457",
"class_name": "person",
"annotation_type": "box",
"annotation": {
"multiple": false,
"coord": {
"x": 275.47,
"y": 49.27,
"width": 86.39999999999998,
"height": 102.25
},
"meta": {},
"difficulty": 0,
"uncertainty": 0.0045
},
"properties": []
},
{
"id": "70257635-801f-4cad-856a-ef0fdbfdf613",
"class_id": "7b8205ef-b251-450c-b628-e6b9cac1a457",
"class_name": "person",
"annotation_type": "box",
"annotation": {
"multiple": false,
"coord": {
"x": 155.64,
"y": 40.61,
"width": 98.34,
"height": 113.05
},
"meta": {},
"difficulty": 0,
"uncertainty": 0.0127
},
"properties": []
}
],
"categories": {
"properties": []
},
"difficulty": 1
}
第 8 步:準備好用于模型訓練的標記數(shù)據(jù)
接下來,使用 SuiteDataset 將 COCO 數(shù)據(jù)從 Suite 導入到模型開發(fā)。SuiteDataset 使 Suite 中導出的數(shù)據(jù)集可以通過 PyTorch 數(shù)據(jù)管道訪問。下面的代碼片段將用于訓練集的 SuiteDataset 對象類進行了實例化。
class SuiteDataset(Dataset):
"""
Instantiate the SuiteDataset object class for training set
"""
def __init__(
self,
team_name: str,
access_key: str,
project_name: str,
export_name: str,
train: bool,
caching_image: bool = True,
transforms: Optional[List[Callable]] = None,
category_names: Optional[List[str]] = None,
):
"""Function to initialize the object class"""
super().__init__()
# Get project setting and export information through the SDK
# Initialize the Python Client
client = spb.sdk.Client(team_name=team_name, access_key=access_key, project_name=project_name)
# Use get_export
export_info = call_with_retry(client.get_export, name=export_name)
# Download the export compressed file through download_url in Export
export_data = call_with_retry(urlopen, export_info.download_url).read()
# Load the export compressed file into memory
with ZipFile(BytesIO(export_data), 'r') as export:
label_files = [f for f in export.namelist() if f.startswith('labels/')]
label_interface = json.loads(export.open('project.json', 'r').read())
category_infos = label_interface.get('object_detection', {}).get('object_classes', [])
cache_dir = None
if caching_image:
cache_dir = f'/tmp/{team_name}/{project_name}'
os.makedirs(cache_dir, exist_ok=True)
self.client = client
self.export_data = export_data
self.categories = [
{'id': i + 1, 'name': cat['name'], 'type': cat['annotation_type']}
for i, cat in enumerate(category_infos)
]
self.category_id_map = {cat['id']: i + 1 for i, cat in enumerate(category_infos)}
self.transforms = build_transforms(train, self.categories, transforms, category_names)
self.cache_dir = cache_dir
# Convert label_files to numpy array and use
self.label_files = np.array(label_files).astype(np.string_)
def __len__(self):
"""Function to return the number of label files"""
return len(self.label_files)
def __getitem__(self, idx):
"""Function to get an item"""
idx = idx if idx >= 0 else len(self) + idx
if idx < 0 or idx >= len(self):
raise IndexError(f'index out of range')
image_id = idx + 1
label_file = self.label_files[idx].decode('ascii')
# Load label information corresponding to idx from the export compressed file into memory
with ZipFile(BytesIO(self.export_data), 'r') as export:
label = load_label(export, label_file, self.category_id_map, image_id)
# Download the image through the Suite sdk based on label_id
try:
image = load_image(self.client, label['label_id'], self.cache_dir)
# Download data in real time using get_data from Suite sdk
except Exception as e:
print(f'Failed to load the {idx}-th image due to {repr(e)}, getting {idx + 1}-th data instead')
return self.__getitem__(idx + 1)
target = {
'image_id': image_id,
'label_id': label['label_id'],
'annotations': label['annotations'],
}
if self.transforms is not None:
image, target = self.transforms(image, target)
return image, target
請以類似的方式處理測試集。下面的代碼片段通過包裹 SuiteDataset 使其與 Torchvision COCOEvaluator 兼容,將用于測試集的 SuiteCocoDataset 對象類實例化。
class SuiteCocoDataset(C.CocoDetection):
"""
Instantiate the SuiteCocoDataset object class for test set
(by wrapping SuiteDataset to make compatible with torchvision's official COCOEvaluator)
"""
def __init__(
self,
team_name: str,
access_key: str,
project_name: str,
export_name: str,
train: bool,
caching_image: bool = True,
transforms: Optional[List[Callable]] = None,
category_names: Optional[List[str]] = None,
num_init_workers: int = 20,
):
"""Function to initialize the object class"""
super().__init__(img_folder='', ann_file=None, transforms=None)
# Call the SuiteDataset class
dataset = SuiteDataset(
team_name, access_key, project_name, export_name,
train=False, transforms=[],
caching_image=caching_image, category_names=category_names,
)
self.client = dataset.client
self.cache_dir = dataset.cache_dir
self.coco = build_coco_dataset(dataset, num_init_workers)
self.ids = list(sorted(self.coco.imgs.keys()))
self._transforms = build_transforms(train, dataset.categories, transforms, category_names)
def _load_image(self, id: int):
"""Function to load an image"""
label_id = self.coco.loadImgs(id)[0]['label_id']
image = load_image(self.client, label_id, self.cache_dir)
return image
def __getitem__(self, idx):
"""Function to get an item"""
try:
return super().__getitem__(idx)
except Exception as e:
print(f'Failed to load the {idx}-th image due to {repr(e)}, getting {idx + 1}-th data instead')
return self.__getitem__(idx + 1)
然后,可以將 SuiteDataset 和 SuiteCocoDataset 用于您的訓練代碼。下面的代碼片段說明了如何使用它們。在模型開發(fā)過程中,可以使用 train_loader 進行訓練并使用 test_loader 進行評估。
train_dataset = SuiteDataset(
team_name=args.team_name,
access_key=args.access_key,
project_name=args.project_name,
export_name=args.train_export_name,
caching_image=args.caching_image,
train=True,
)
test_dataset = SuiteCocoDataset(
team_name=args.team_name,
access_key=args.access_key,
project_name=args.project_name,
export_name=args.test_export_name,
caching_image=args.caching_image,
train=False,
num_init_workers=args.workers,
)
train_loader = DataLoader(
num_workers=args.workers,
batch_sampler=G.GroupedBatchSampler(
RandomSampler(train_dataset),
k=3),
args.batch_size,
),
collate_fn=collate_fn,
)
test_loader = DataLoader(
num_workers=args.workers,
sampler=SequentialSampler(test_dataset), batch_size=1,
collate_fn=collate_fn,
)
第 9 步:使用 NVIDIA TAO Toolkit 訓練您的模型
現(xiàn)在,可以將 Suite 注釋的數(shù)據(jù)用于訓練您的對象檢測模型了。TAO Toolkit 使您能夠訓練、微調、修剪和輸出經(jīng)過高度優(yōu)化的高精度計算機視覺模型,以便根據(jù)數(shù)據(jù)采用流行的網(wǎng)絡架構和骨干網(wǎng)來完成部署。在本次教學中,您可以選擇 TAO 自帶的對象檢測模型 YOLO v4。
首先,從 TAO Toolkit 快速入門(https://catalog.ngc.nvidia.com/orgs/nvidia/teams/tao/resources/tao-getting-started)下載適用于 notebook 的樣本。
pip3 install nvidia-tao
wget --content-disposition https://api.ngc.nvidia.com/v2/resources/nvidia/tao/tao-getting-started/versions/4.0.1/zip -O getting_started_v4.0.1.zip
$ unzip -u getting_started_v4.0.1.zip -d ./getting_started_v4.0.1 && rm -rf getting_started_v4.0.1.zip && cd ./getting_started_v4.0.1
接下來,使用下面的代碼啟動notebook:
jupyter notebook --ip 0.0.0.0 --port 8888 --allow-root
在 localhost 上打開網(wǎng)頁瀏覽器并前往以下地址:
http://0.0.0.0:8888
如要創(chuàng)建一個 YOLO v4 模型,請打開:
notebooks/tao_launcher_starter_kit/yolo_v4/yolo_v4.ipynb and follow the
并按照notebook上的說明訓練模型。
根據(jù)結果對模型進行微調,直到達到指標要求。如果需要的話,您可以在這個階段創(chuàng)建您自己的主動學習循環(huán)。在現(xiàn)實場景中,查詢預測失敗的樣本,指派人工標記員對這批新的樣本數(shù)據(jù)進行注釋,并使用新標記的訓練數(shù)據(jù)補充您的模型。在隨后的幾輪模型開發(fā)中,Superb AI 套件可以進一步協(xié)助您進行數(shù)據(jù)采集和注釋,從而反復提高模型的性能。
使用 TAO Toolkit 4.0,無需任何 AI 專業(yè)知識,可以更加輕松地開始創(chuàng)建高精度的模型??梢允褂?AutoML 自動微調您的超參數(shù)、體驗一鍵將 TAO Toolkit 部署到各種云服務中、將 TAO Toolkit 與第三方 MLOPs 服務集成并探索新的基于 Transformer 的視覺模型 (CitySemSegformer, Peoplenet Transformer)。
總結
計算機視覺領域的數(shù)據(jù)標記會帶來許多獨特的挑戰(zhàn)。由于需要標記的數(shù)據(jù)量大,這個過程可能十分困難且昂貴。此外,由于這個過程是主觀的,使得在一個大型數(shù)據(jù)集中實現(xiàn)一致的高質量標記輸出非常困難。
由于需要調整和優(yōu)化許多算法與超參數(shù),模型訓練也可能極具挑戰(zhàn)性。在這個過程中,需要對數(shù)據(jù)和模型有深刻的了解,并進行大量實驗才能達到最佳效果。此外,訓練計算機視覺模型往往需要耗費大量算力,因此在預算和時間有限的情況下很難做到。
Superb AI Suite 能夠幫助您采集和標記高質量的計算機視覺數(shù)據(jù)集,而 NVIDIA TAO Toolkit 使您能夠優(yōu)化預先訓練的計算機視覺模型。將兩者相結合,就可以在不犧牲質量的前提下,大幅縮短計算機視覺應用的開發(fā)時間。
更多信息,敬請訪問:
-
TAO Toolkit Google Colab notebook(https://colab.research.google.com/github/NVIDIA-AI-IOT/nvidia-tao/blob/main/tensorflow/yolo_v4/yolo_v4.ipynb)
-
TAO Toolkit 文檔(https://docs.nvidia.com/tao/tao-toolkit/index.html)
-
Superb AI Suite 標記平臺(https://superb-ai.com/product/labeling/)
-
Superb AI Suite 文檔(https://docs.superb-ai.com/docs/)
原文標題:利用 Superb AI Suite 和 NVIDIA TAO Toolkit 創(chuàng)建高質量的計算機視覺應用
文章出處:【微信公眾號:NVIDIA英偉達】歡迎添加關注!文章轉載請注明出處。
-
英偉達
+關注
關注
22文章
3953瀏覽量
93821
原文標題:利用 Superb AI Suite 和 NVIDIA TAO Toolkit 創(chuàng)建高質量的計算機視覺應用
文章出處:【微信號:NVIDIA_China,微信公眾號:NVIDIA英偉達】歡迎添加關注!文章轉載請注明出處。
發(fā)布評論請先 登錄
NVIDIA技術賦能歐洲最快超級計算機JUPITER
NVIDIA助力全球最大量子研究超級計算機
NVIDIA GTC2025 亮點 NVIDIA推出 DGX Spark個人AI計算機

NVIDIA 宣布推出 DGX Spark 個人 AI 計算機

NVIDIA推出個人AI超級計算機Project DIGITS
聯(lián)發(fā)科與NVIDIA合作 為NVIDIA 個人AI超級計算機設計NVIDIA GB10超級芯片
借助谷歌Gemini和Imagen模型生成高質量圖像

《CST Studio Suite 2024 GPU加速計算指南》
NVIDIA助力xAI打造全球最大AI超級計算機
NVIDIA 以太網(wǎng)加速 xAI 構建的全球最大 AI 超級計算機

評論