manjaro使用心得 / 中文(注音)輸入法調整
最近決定要將正式從windows畢業,投入linux的懷抱。在接受擁抱前,我決定先用虛擬機測試,寫下調整環境的方法。
在訓練模型時,需要大量的訓練資料,這時就會需要許多公開的數據集,在動作偵測(pose estimation)方面,<strong>標注資料是人體關節</strong>(keypoint)的數據集很多,COCO 就是其中一個。 <br /><br /> 而且在 github 上找 code 的時候,因為數據集龐大的關係,所以並不會把訓練資料一併上傳至 repository 裡,因此需要自行去找到數據集下載。 <br /><br /> 廢話不多說,開始吧。 <br /><br /><br />
["annotations"]["image_id"] == ["images"]["id"]
``` ["annotations"]: "image_id", "category_id", "bbox", "num_keypoints", "keypoints" ["images"]: "file_name", "width", "height", "id" ``` ```python import os import json import tensorflow as tf annotations_file = 'person_keypoints_train2014.json' # 下載的 json 存放路徑,記得解壓縮 images_dir = 'train2014/' # 下載的對應圖片的資料夾路徑,記得解壓縮,斜線可加可不加 def print_human_info(image, annotation, images_dir): """ Args: image: dict annotation: dict images_dir: string. directory containing the image files. """ category_id = int(annotation['category_id']) if category_id != 1: # 如果類別不是人 print('\tcategory of ', image['file_name'], "isn't human.") return if annotation['num_keypoints'] <= 0: # 如果可見keypoints少於指定數量 print('\tnumber of keypoints of ', image['file_name'], 'is less than wanted.') return print('file information:') #print('\tfile name: ', image['file_name']) #print('\timage id: ', image['id']) #print('\timage height: ',image['height']) #print('\timage width: ',image['width']) #print('\timage path: ', os.path.join(images_dir, image['file_name'])) (x, y, width, height) = tuple(annotation['bbox']) #print('\tbounding box width: ', annotation['bbox'][2]) #print('\tbounding box height: ', annotation['bbox'][3]) # ["keypoints"]存放是[ x,y,v, x,y,v, x,y,v, ... ] keypoints_x = annotation['keypoints'][0::3] keypoints_y = annotation['keypoints'][1::3] keypoints_v = annotation['keypoints'][2::3] #print('\tkeypoints:') #print('\t\t', keypoints_x) #print('\t\t', keypoints_y) #print('\t\t', keypoints_v) with tf.gfile.GFile(annotations_file, 'r') as fid: groundtruth_data = json.load(fid) # 用["images"]["id"]去做index,取得["images"]的資訊 image_info = {} for image in groundtruth_data['images']: image_info[image['id']] = {'id': image['id'], 'height': image['height'], 'width': image['width'], 'file_name': image['file_name']} # 按照讀到的annotation順序,依序去讀取image資料 for idx, annotation in enumerate(groundtruth_data['annotations']): image = image_info[annotation['image_id']] if idx % 10000 == 0: # 資料集很大,取幾個示意 print(idx) print_human_info(image, annotation, images_dir) ``` ### 參考 [tensorflow/models/research/object_detection/dataset_tools/create_coco_tf_record.py](https://github.com/tensorflow/models/blob/master/research/object_detection/dataset_tools/create_coco_tf_record.py), by pkulzc, from github
留言
張貼留言