-
Notifications
You must be signed in to change notification settings - Fork 4
Fix export of video task for coco, yolo, PascalVOC #137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
|
||
| def export_coco( | ||
| self, | ||
| project: str, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
タスクを動画と画像のいずれで処理すべきかを判断するために、プロジェクトタイプを用いることにしました。
そのため、SDK利用者に新たにプロジェクトスラグを指定してもらうようにしました。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
こちら今後project_slugが必須になると思うので、READMEの方もそれに合わせて変えておいてもらえると助かります!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
READMEを修正しました!
| } | ||
|
|
||
|
|
||
| def _generate_coco_images( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if annotation_type != AnnotationType.pose_estimation.value and ( | ||
| not points or (len(points) == 0) | ||
| ): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
既知のバグの修正。
| def __get_coco_category_by_name(categories: list, name: str) -> Optional[dict]: | ||
| matched_categories = [ | ||
| category for category in categories if category["name"] == name | ||
| ] | ||
| if len(matched_categories) >= 1: | ||
| return matched_categories[0] | ||
| return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
既知のバグの修正
| @contextmanager | ||
| def VideoCapture(*args, **kwds): | ||
| videoCapture = cv2.VideoCapture(*args, **kwds) | ||
| try: | ||
| yield videoCapture | ||
| finally: | ||
| videoCapture.release() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
withを使った自動リソース開放のためContextManagerを使います。
| videoCapture.release() | ||
|
|
||
|
|
||
| def _download_file(url: str, output_file_path: str, chunk_size: int = 8192) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
チャンクサイズは適切なものが推測しづらいので、ひとまずの値です。将来的には、利用者が指定できるようにしてもよいかもしれません。
| with NamedTemporaryFile(prefix="fastlabel-sdk-") as video_file: | ||
| video_file_path = _download_file( | ||
| url=video_task["url"], output_file_path=video_file.name | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
動画ファイルは一時ファイルとして書き込み、withを抜けたら削除されるようにしています。
OSやPythonランタイムによりますが、xnuxでCPythonならおおよそ /tmp/fastlabel-sdk-xxxx になるはずです。
| def is_video_project_type(project_type: str): | ||
| return type(project_type) is str and project_type.startswith("video_") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
文字の前方一致で判断します。
他の類似コードではすべてのタイプを定数化して一致判定していることがほとんどですが、定数の管理コストを考えて前方一致で判定することにしました。問題があるようなら指摘してください。
see: https://github.com/fastlabel/fastlabel-application/issues/3475
補足
WebのExportの動作と極力合わせていますが、一部異なります。
問題がありそうなら指摘をお願いします。
特に1。Webではアノテーションがないタスクでもアノテーションファイルを出力していますが、SDKではアノテーションがないタスクのアノテーションファイルは出力しません。また、いくつか既存のバグを発見し影響があるものは修正しましたが、以下は大きな影響がないため ueno さんと相談してコメントを残すのみとしています。
categoriesのcolorがすべて同じになります。テスト
WebとSDKのぞれぞれで、動画タスクをCOCO、YOLO、PascalVOCでエクスポートし、Diffツールで差分を確認しました。