JSONだったら読めるのでは??
要約
- 前回は日本語が使えない開発機で下記の記事を書いたので、ちょっと微妙な内容?
- データ、特にコンフィグとjsonファイルに問題があると学習ができないのがMMDetectionの難しいところ
- でも、いろいろなモデルが試せるのは捨てがたい。
- 私の環境はPytorch(Ubuntu 22.04)
- 私にスキルはほとんどない(ここ重要)
コンフィグ作成時の注意点
- 基本的に使用したいモデルの中に作っておくとパスが統一しやすい(エラー対策)
- 普通に学習済みモデルをつかうと学習時間が大変なことに・・・(カスタム時は上手く編集!)
English
create custom config
- Each model config refer to base directory config
- To avoid wrong path failure, cofing.py should pay attention to directory structure.
JSONファイルをMMDetectionに最適化する
Error example
terminal
Traceback (most recent call last):
File "/home/kanengi/anaconda3/envs/mmlab/lib/python3.8/site-packages/mmengine/config/config.py", line 245, in _validate_py_syntax
ast.parse(content)
File "/home/kanengi/anaconda3/envs/mmlab/lib/python3.8/ast.py", line 47, in parse
return compile(source, filename, mode, flags,
File "<unknown>", line 39
)
^
SyntaxError: unmatched ')'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "tools/train.py", line 133, in <module>
main()
File "tools/train.py", line 70, in main
cfg = Config.fromfile(args.config)
File "/home/kanengi/anaconda3/envs/mmlab/lib/python3.8/site-packages/mmengine/config/config.py", line 178, in fromfile
cfg_dict, cfg_text, env_variables = Config._file2dict(
File "/home/kanengi/anaconda3/envs/mmlab/lib/python3.8/site-packages/mmengine/config/config.py", line 487, in _file2dict
for base_cfg_path in Config._get_base_files(temp_config_file.name):
File "/home/kanengi/anaconda3/envs/mmlab/lib/python3.8/site-packages/mmengine/config/config.py", line 645, in _get_base_files
Config._validate_py_syntax(filename)
File "/home/kanengi/anaconda3/envs/mmlab/lib/python3.8/site-packages/mmengine/config/config.py", line 247, in _validate_py_syntax
raise SyntaxError('There are syntax errors in config '
SyntaxError: There are syntax errors in config file /tmp/tmpj5ljio33/tmpb_j4rhtr.py: unmatched ')' (<unknown>, line 39)
Exception ignored in: <function _TemporaryFileCloser.__del__ at 0x7fd8778a2160>
Traceback (most recent call last):
File "/home/kanengi/anaconda3/envs/mmlab/lib/python3.8/tempfile.py", line 440, in __del__
self.close()
File "/home/kanengi/anaconda3/envs/mmlab/lib/python3.8/tempfile.py", line 436, in close
unlink(self.name)
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmpj5ljio33/tmpb_j4rhtr.py'
JSON ファイルを作るtoolといえば
- この2ツールでしょうか。特にcoco-annotatorは純正的ですよね⁉
Label StudioではExportでCOCOを選択します。
見出しh2 Problem
English comment
create custom config
- This coco zip file is result.coco + images folder
- So we have to set data folder all file unless you want to avoid train failure.
- But for training, we want to divide train and val folder
- What should I do????
JSONファイルで発生する問題
English comment
coco json format structure
- image data information area
- classification
- annotation information area
json
{
"images": [
{
"width": 512,
"height": 512,
"id": 0,
"file_name": "images/ccea0662-0d668a32-pass.00014.png"
},
],
"categories": [
{
"id": 0,
"name": "cup"
},
{
"id": 1,
"name": "ng"
},
{
"id": 2,
"name": "other"
}
],
"annotations": [
{
"id": 0,
"image_id": 0,
"category_id": 0,
"segmentation": [],
"bbox": [
19.372972972972978,
63.19279279279281,
326.11171171171173,
427.12792792792794
],
"ignore": 0,
"iscrowd": 0,
"area": 139291.41969645323
},
}
],
"info": {
"year": 2023,
"version": "1.0",
"description": "",
"contributor": "Label Studio",
"url": "",
"date_created": "2023-06-13 01:44:38.407576"
}
}
- for my solution is debeloped coco json converter! ;)
coco-annotator
-
どうも何度も書いたり消したりするとラベルのID不一致が発生
- 学習が成功してもラベル違いが出る場合の原因
-
IDコンバータを作ってみたが、どうも合わない・・・(そりゃそうでしょうね)
Label Studio
-
imageフォルダが作られて、ネーミングも変わっている。
- JSONがリネームされたサブフォルダを参照となっているので、そのまま使うのは難しい
-
(もしかしたら、Train,Valでわければよかった?)
-
ただし、標準機の機能で分類はされるようですが・・・
JSONファイルの中身を見てみます。
json
{
"images": [
{
"width": 512,
"height": 512,
"id": 0,
"file_name": "images/ccea0662-0d668a32-pass.00014.png"
},
],
"categories": [
{
"id": 0,
"name": "cup"
},
{
"id": 1,
"name": "ng"
},
{
"id": 2,
"name": "other"
}
],
"annotations": [
{
"id": 0,
"image_id": 0,
"category_id": 0,
"segmentation": [],
"bbox": [
19.372972972972978,
63.19279279279281,
326.11171171171173,
427.12792792792794
],
"ignore": 0,
"iscrowd": 0,
"area": 139291.41969645323
},
}
],
"info": {
"year": 2023,
"version": "1.0",
"description": "",
"contributor": "Label Studio",
"url": "",
"date_created": "2023-06-13 01:44:38.407576"
}
}
- 画像情報
- アノテーションのID情報
- 画像のアノテーションした情報
となっていますね。
手書きやらエディタの変換機能では難しそう
- Label Studio cocoデータ変換ツールを作って対応しました。
- imageファイルに付加される接頭辞を削除、上記の規則に沿って並び替え。
学習できるようになりました。
補足1
Web camで表示してみましたが、バウンディングボックスの色が全部同じだったので、変更せねば・・・
補足2
COCO Annotatorの再セットアップに挫折して上記の通りとなりました。