1 line
15 KiB
Plaintext
1 line
15 KiB
Plaintext
|
{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[],"authorship_tag":"ABX9TyM4q90TKm68+fCgyse7d3la"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"code","execution_count":1,"metadata":{"id":"YgcHkg_E9b9U","executionInfo":{"status":"ok","timestamp":1675102221170,"user_tz":-60,"elapsed":14,"user":{"displayName":"marti Xooo","userId":"17000102553335328898"}}},"outputs":[],"source":["import os\n","import cv2\n","from xml.etree.ElementTree import ElementTree\n","import re\n","import random\n","import numpy as np\n","from os.path import join\n","\n"]},{"cell_type":"code","source":["!fusermount -u drive\n","!google-drive-ocamlfuse drive"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"hQ_r-pBSMknR","executionInfo":{"status":"ok","timestamp":1675090876283,"user_tz":-60,"elapsed":464,"user":{"displayName":"marti Xooo","userId":"17000102553335328898"}},"outputId":"0d2877c8-d320-4d0b-e9f3-43f52fe51eae"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["shell-init: error retrieving current directory: getcwd: cannot access parent directories: Transport endpoint is not connected\n","fusermount: bad mount point drive: Transport endpoint is not connected\n","shell-init: error retrieving current directory: getcwd: cannot access parent directories: Transport endpoint is not connected\n","/bin/bash: google-drive-ocamlfuse: command not found\n"]}]},{"cell_type":"code","source":["from google.colab import drive\n","drive.mount('/content/gdrive', force_remount=True)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"6Mqg8_uIEau4","executionInfo":{"status":"ok","timestamp":1675102254260,"user_tz":-60,"elapsed":33102,"user":{"displayName":"marti Xooo","userId":"17000102553335328898"}},"outputId":"d04814c8-39f1-4b53-e031-837f255d86f4"},"execution_count":2,"outputs":[{"output_type":"stream","name":"stdout","text":["Mounted at /content/gdrive\n"]}]},{"cell_type":"code","source":["cd gdrive/MyDrive/WKO_PROJECT_NEW"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"yF5SmBNFEdjJ","executionInfo":{"status":"ok","timestamp":1675102254261,"user_tz":-60,"elapsed":13,"user":{"displayName":"marti Xooo","userId":"17000102553335328898"}},"outputId":"c078f765-06c8-417d-d4c9-32b83f74c610"},"execution_count":3,"outputs":[{"output_type":"stream","name":"stdout","text":["/content/gdrive/MyDrive/WKO_PROJECT_NEW\n"]}]},{"cell_type":"code","source":["# convert voc annotation format to darknet format\n","def xml_to_darknet(path):\n"," root = ElementTree().parse(path)\n","\n"," img_path = root.find('filename').text.replace('png','txt')\n"," img_size = root.find('size')\n"," width = int(img_size.find('width').text)\n"," height = int(img_size.find('height').text)\n"," with open('mask_dataset/labels/' + img_path, 'w') as f:\n"," lines = []\n"," \n"," for node in root.findall('object'):\n"," object_ = dict(class_=None, x=None, y=None, width=None, height=None)\n"," \n"," # class\n"," class_name = node.find('name').text\n","\n"," if(class_name == 'without_mask'):\n"," object_['class_'] = '0'\n"," elif(class_name == 'with_mask'):\n"," object_['class_'] = '1'\n"," else:\n"," object_['class_'] = '2'\n"," \n"," # bounding box\n"," bnd_box = node.find(\"bndbox\")\n"," x_min = float(bnd_box[0].text)\n"," y_min = float(bnd_box[1].text)\n"," x_max = float(bnd_box[2].text)\n"," y_max = float(bnd_box[3].text)\n","\n"," dw = float(1/width)\n"," dh = float(1/height)\n","\n"," w = float(x_max - x_min)\n"," h = float(y_max - y_min)\n","\n"," x = float((x_min + x_max)/2 -1)\n"," y = float((y_min + y_max)/2 -1)\n","\n"," w = float(w * dw)\n"," h = float(h * dh)\n"," x = float(x * dw)\n"," y
|