feat: create Untitled.ipynb and img.xml
Browse files- Processing/Untitled.ipynb +119 -0
- Processing/img.xml +26 -0
Processing/Untitled.ipynb
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": 45,
|
| 6 |
+
"id": "8ed070be-f7e8-49dd-bc82-41bbf94c2a31",
|
| 7 |
+
"metadata": {},
|
| 8 |
+
"outputs": [],
|
| 9 |
+
"source": [
|
| 10 |
+
"from glob import glob\n",
|
| 11 |
+
"\n",
|
| 12 |
+
"path = \"/workspace/Archives/Training/*.json\"\n",
|
| 13 |
+
"\n",
|
| 14 |
+
"datasetFiles = sorted(glob(path))"
|
| 15 |
+
]
|
| 16 |
+
},
|
| 17 |
+
{
|
| 18 |
+
"cell_type": "code",
|
| 19 |
+
"execution_count": 46,
|
| 20 |
+
"id": "8f2aff86-c2dc-438c-95ea-badebbd02693",
|
| 21 |
+
"metadata": {},
|
| 22 |
+
"outputs": [],
|
| 23 |
+
"source": [
|
| 24 |
+
"from pascal_voc_writer import Writer\n",
|
| 25 |
+
"from tqdm import tqdm\n",
|
| 26 |
+
"import json\n",
|
| 27 |
+
"\n",
|
| 28 |
+
"for file in tqdm(datasetFiles):\n",
|
| 29 |
+
" try:\n",
|
| 30 |
+
" fileLoad = open(path+file, \"r\", encoding=\"utf8\")\n",
|
| 31 |
+
" fileLoad = json.load(fileLoad)\n",
|
| 32 |
+
" except:\n",
|
| 33 |
+
" print(file)\n",
|
| 34 |
+
" \n",
|
| 35 |
+
" for num in range(len(fileLoad['images'])):\n",
|
| 36 |
+
" fileName = str(fileLoad['images'][num]['file_name']).split(\".\")[0]\n",
|
| 37 |
+
" \n",
|
| 38 |
+
" image_w = fileLoad['images'][num]['width']\n",
|
| 39 |
+
" image_h = fileLoad['images'][num]['height']\n",
|
| 40 |
+
" \n",
|
| 41 |
+
" writer = Writer(database='X-ray_multi_object_recognition_data', \n",
|
| 42 |
+
" path=fileLoad['images'][num]['file_name'], \n",
|
| 43 |
+
" width=image_w, height=image_h, \n",
|
| 44 |
+
" depth=3, segmented=len(fileLoad['annotations']))\n",
|
| 45 |
+
" \n",
|
| 46 |
+
" for objectNum in range(len(fileLoad['annotations'])):\n",
|
| 47 |
+
" x, y, w, h = fileLoad['annotations'][objectNum]['bbox']\n",
|
| 48 |
+
" label = fileLoad['categories'][objectNum]['name']\n",
|
| 49 |
+
" \n",
|
| 50 |
+
" writer.addObject(label, x, y, x+w, y+h)\n",
|
| 51 |
+
" \n",
|
| 52 |
+
" writer.save(f'{fileName}.xml')"
|
| 53 |
+
]
|
| 54 |
+
},
|
| 55 |
+
{
|
| 56 |
+
"cell_type": "code",
|
| 57 |
+
"execution_count": 47,
|
| 58 |
+
"id": "7139d6cc-1e86-4797-8bf4-23ee33836259",
|
| 59 |
+
"metadata": {},
|
| 60 |
+
"outputs": [
|
| 61 |
+
{
|
| 62 |
+
"data": {
|
| 63 |
+
"text/plain": [
|
| 64 |
+
"{'images': [{'id': 0,\n",
|
| 65 |
+
" 'file_name': 'E3S690_20220810_012120_S_Pistol_002-001_1.png',\n",
|
| 66 |
+
" 'angle': 0,\n",
|
| 67 |
+
" 'height': 760,\n",
|
| 68 |
+
" 'width': 896}],\n",
|
| 69 |
+
" 'annotations': [{'id': 0,\n",
|
| 70 |
+
" 'image_id': 0,\n",
|
| 71 |
+
" 'iscrowd': 1,\n",
|
| 72 |
+
" 'category_id': 1,\n",
|
| 73 |
+
" 'bbox': [365.0, 222.0, 130.0, 232.0],\n",
|
| 74 |
+
" 'area': 13110.0,\n",
|
| 75 |
+
" 'segmentation': {'size': [760, 896],\n",
|
| 76 |
+
" 'counts': '_U_89mf0c0]Oc0E9O2N2000000001O01O01O001O01O01O00010O001O00010O00001O010O00001O01O01O00010O001O00010O00001O0100O1O100O3M4M>A>C1N2N1O2N2M^Og[OhMXd0U2m[OiMSd0V2P\\\\OhMoc0X2R\\\\OiMlc0X2U\\\\OgMic0[2W\\\\OfMgc0[2Y\\\\OeMec0\\\\2]\\\\OcMac0_2_\\\\ObMXc0f2h\\\\OZMQc0m2n\\\\OTMRc0l2n\\\\OTMRc0m2l\\\\OTMSc0m2m\\\\OSMTc0l2k\\\\OUMUc0l2i\\\\OUMWc0n2`\\\\OXM`c0a3100023O5H8F:F5KO000006J<D;E<C7I010O1N2M3L4N20000000aIW_Oo5m`0iIY_OU6Ua001O0002111J4M1RJa^Oa5_a0_Jo^OS5Ra0kJ]_Og4d`0XKj_OY4W`0gKW@k3Yb0B>B?A`0\\\\Od0\\\\Od0_O9G2N2N2N[VY9'}}],\n",
|
| 77 |
+
" 'categories': [{'id': 1, 'name': 'Pistol', 'supercategory': None}],\n",
|
| 78 |
+
" 'meta': [{'object_id': '002-001',\n",
|
| 79 |
+
" 'material_outside': 'X',\n",
|
| 80 |
+
" 'material_inside': 'Plastic',\n",
|
| 81 |
+
" 'size': '24',\n",
|
| 82 |
+
" 'unit': 'cm'}]}"
|
| 83 |
+
]
|
| 84 |
+
},
|
| 85 |
+
"execution_count": 47,
|
| 86 |
+
"metadata": {},
|
| 87 |
+
"output_type": "execute_result"
|
| 88 |
+
}
|
| 89 |
+
],
|
| 90 |
+
"source": [
|
| 91 |
+
"path = \"/workspace/Archives/Training/E3S690_20220810_012120_S_Pistol_002-001_1.json\"\n",
|
| 92 |
+
"\n",
|
| 93 |
+
"fileLoad = open(path, \"r\", encoding=\"utf8\")\n",
|
| 94 |
+
"json.load(fileLoad)"
|
| 95 |
+
]
|
| 96 |
+
}
|
| 97 |
+
],
|
| 98 |
+
"metadata": {
|
| 99 |
+
"kernelspec": {
|
| 100 |
+
"display_name": "Python 3 (ipykernel)",
|
| 101 |
+
"language": "python",
|
| 102 |
+
"name": "python3"
|
| 103 |
+
},
|
| 104 |
+
"language_info": {
|
| 105 |
+
"codemirror_mode": {
|
| 106 |
+
"name": "ipython",
|
| 107 |
+
"version": 3
|
| 108 |
+
},
|
| 109 |
+
"file_extension": ".py",
|
| 110 |
+
"mimetype": "text/x-python",
|
| 111 |
+
"name": "python",
|
| 112 |
+
"nbconvert_exporter": "python",
|
| 113 |
+
"pygments_lexer": "ipython3",
|
| 114 |
+
"version": "3.12.4"
|
| 115 |
+
}
|
| 116 |
+
},
|
| 117 |
+
"nbformat": 4,
|
| 118 |
+
"nbformat_minor": 5
|
| 119 |
+
}
|
Processing/img.xml
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<annotation>
|
| 2 |
+
<folder>Processing</folder>
|
| 3 |
+
<filename>E3S690_20220810_012120_S_Pistol_002-001_1.png</filename>
|
| 4 |
+
<path>/workspace/Processing/E3S690_20220810_012120_S_Pistol_002-001_1.png</path>
|
| 5 |
+
<source>
|
| 6 |
+
<database>X-ray_multi_object_recognition_data</database>
|
| 7 |
+
</source>
|
| 8 |
+
<size>
|
| 9 |
+
<width>896</width>
|
| 10 |
+
<height>760</height>
|
| 11 |
+
<depth>3</depth>
|
| 12 |
+
</size>
|
| 13 |
+
<segmented>0</segmented>
|
| 14 |
+
<object>
|
| 15 |
+
<name>Pistol</name>
|
| 16 |
+
<pose>Unspecified</pose>
|
| 17 |
+
<truncated>0</truncated>
|
| 18 |
+
<difficult>0</difficult>
|
| 19 |
+
<bndbox>
|
| 20 |
+
<xmin>365.0</xmin>
|
| 21 |
+
<ymin>222.0</ymin>
|
| 22 |
+
<xmax>495.0</xmax>
|
| 23 |
+
<ymax>454.0</ymax>
|
| 24 |
+
</bndbox>
|
| 25 |
+
</object>
|
| 26 |
+
</annotation>
|