Skip to content

Commit

Permalink
Created using Colaboratory
Browse files Browse the repository at this point in the history
  • Loading branch information
sudhir2016 committed Jun 26, 2020
1 parent 716250e commit 1dee032
Showing 1 changed file with 192 additions and 0 deletions.
192 changes: 192 additions & 0 deletions Wheat_data1.ipynb
Original file line number Diff line number Diff line change
@@ -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": [
"<a href=\"https://colab.research.google.com/github/sudhir2016/Alexa/blob/master/Wheat_data1.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"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": []
}
]
}

0 comments on commit 1dee032

Please sign in to comment.