[974c13]: / AnalysisCodes / SSD / labels_generator.ipynb

Download this file

84 lines (83 with data), 2.5 kB

{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import csv\n",
    "\n",
    "output = []\n",
    "\n",
    "with open('trains.txt') as filenames:\n",
    "    reader = csv.reader(filenames)\n",
    "    for filename in reader:\n",
    "        with open('bounding_boxes/' + filename[0][:-4] + '.txt') as bb:\n",
    "            line = bb.readline().strip().split()\n",
    "            while line:\n",
    "                minx = line[0].split('.')[0]\n",
    "                miny = line[1].split('.')[0] \n",
    "                maxx = line[2].split('.')[0] \n",
    "                maxy = line[3].split('.')[0] \n",
    "                output.append(filename[0][:-4] +'.jpg'+',1,'+minx+','+miny+','+maxx+','+maxy)\n",
    "                line = bb.readline().strip().split()\n",
    "with open('trainlabels.csv', '+w') as labels:\n",
    "    for i in output:\n",
    "        labels.write(i + '\\n')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "output = []\n",
    "with open('testimages.txt') as filenames:\n",
    "    reader = csv.reader(filenames)\n",
    "    for filename in reader:\n",
    "        with open('bounding_boxes/' + filename[0][:-4] + '.txt') as bb:\n",
    "            line = bb.readline().strip().split()\n",
    "            while line:\n",
    "                minx = line[0].split('.')[0]\n",
    "                miny = line[1].split('.')[0] \n",
    "                maxx = line[2].split('.')[0] \n",
    "                maxy = line[3].split('.')[0] \n",
    "                output.append(filename[0][:-4]+'.jpg'+ ',1,'+minx+','+miny+','+maxx+','+maxy)\n",
    "                line = bb.readline().strip().split()\n",
    "with open('testlabels.csv', '+w') as labels:\n",
    "    for i in output:\n",
    "        labels.write(i + '\\n')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}