diff --git a/Wheat_data1.ipynb b/Wheat_data1.ipynb new file mode 100644 index 0000000..d5bfbcf --- /dev/null +++ b/Wheat_data1.ipynb @@ -0,0 +1,192 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "Wheat_data1.ipynb", + "provenance": [], + "authorship_tag": "ABX9TyOZF03hz3dNCf9iiIeCPJnP", + "include_colab_link": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "08ATK1f8P0yB", + "colab_type": "code", + "colab": {} + }, + "source": [ + "import pandas as pd\n", + "import os\n", + "import numpy as np" + ], + "execution_count": 2, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "9YWtzV1SQCVj", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 51 + }, + "outputId": "436d428c-3573-49dd-b3c3-c70da06366dd" + }, + "source": [ + "!unzip train.csv.zip" + ], + "execution_count": 3, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Archive: train.csv.zip\n", + " inflating: train.csv \n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "M97dz7ZRRF7s", + "colab_type": "code", + "colab": {} + }, + "source": [ + "train=pd.read_csv(\"train.csv\")" + ], + "execution_count": 4, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "Tu2wvGBST28T", + "colab_type": "code", + "colab": {} + }, + "source": [ + "def convert_to_yolo(bbox, c=1024.0):\n", + " bbox=np.fromstring(bbox[1:-1],sep=',')\n", + " x=(bbox[0]+bbox[2]/2.0)/c\n", + " y=(bbox[1]+bbox[3]/2.0)/c\n", + " w= bbox[2]/c\n", + " h=bbox[3]/c\n", + " yolo_box=[x,y,w,h]\n", + " return(yolo_box)\n" + ], + "execution_count": 5, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "h4GQ59QPXGOC", + "colab_type": "code", + "colab": {} + }, + "source": [ + "train['yolo_box'] = train.bbox.apply(convert_to_yolo)" + ], + "execution_count": 6, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "rlznSk0Sa3Bh", + "colab_type": "code", + "colab": {} + }, + "source": [ + "unique=train.image_id.unique()" + ], + "execution_count": 7, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "rSKj-vBUEEJI", + "colab_type": "code", + "colab": {} + }, + "source": [ + "for i in unique:\n", + " file= \"%s.txt\" %i\n", + " a='/content/yolo'\n", + " b=file\n", + " path=os.path.join(a,b)\n", + " os.mknod(path)\n", + " file_data= train.query('image_id == \"%s\"' %i)\n", + " boxes = file_data.yolo_box.values\n", + " with open(path, 'a') as file:\n", + " for j in boxes:\n", + " s = \"0 %s %s %s %s \\n\"\n", + " new_line = (s % tuple(j))\n", + " file.write(new_line)\n" + ], + "execution_count": 13, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "oHytY0KZabdr", + "colab_type": "code", + "colab": {} + }, + "source": [ + "f=open('yolo/b53afdf5c.txt')" + ], + "execution_count": 14, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "y0kGx2EqadM7", + "colab_type": "code", + "colab": {} + }, + "source": [ + "print(f.read())" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "nLgcFshxgT3h", + "colab_type": "code", + "colab": {} + }, + "source": [ + "!zip -r /content/yolo.zip /content/yolo" + ], + "execution_count": null, + "outputs": [] + } + ] +} \ No newline at end of file