質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
CSV

CSV(Comma-Separated Values)はコンマで区切られた明白なテキスト値のリストです。もしくは、そのフォーマットでひとつ以上のリストを含むファイルを指します。

深層学習

深層学習は、多数のレイヤのニューラルネットワークによる機械学習手法。人工知能研究の一つでディープラーニングとも呼ばれています。コンピューター自体がデータの潜在的な特徴を汲み取り、効率的で的確な判断を実現することができます。

YOLO

YOLOとは、画像検出および認識用ニューラルネットワークです。CベースのDarknetというフレームワークを用いて、画像や動画からオブジェクトを検出。リアルタイムでそれが何になるのかを認識し、分類することができます。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

1回答

4493閲覧

YOLO形式のデータを作るために実行するconvert.pyがうまくいきません。

buffalo

総合スコア15

CSV

CSV(Comma-Separated Values)はコンマで区切られた明白なテキスト値のリストです。もしくは、そのフォーマットでひとつ以上のリストを含むファイルを指します。

深層学習

深層学習は、多数のレイヤのニューラルネットワークによる機械学習手法。人工知能研究の一つでディープラーニングとも呼ばれています。コンピューター自体がデータの潜在的な特徴を汲み取り、効率的で的確な判断を実現することができます。

YOLO

YOLOとは、画像検出および認識用ニューラルネットワークです。CベースのDarknetというフレームワークを用いて、画像や動画からオブジェクトを検出。リアルタイムでそれが何になるのかを認識し、分類することができます。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2018/12/13 10:18

現在convert.pyを実行するために画像データとテキストデータを作った状態でconvert.pyを実行しようとすると

['out19.csv', 'out11.csv', 'out16.csv', 'out17.csv', 'out12.csv', 'out13.csv', 'out18.csv', 'out14.csv', 'out15.csv', 'out10.csv', 'out6.csv', 'out2.csv', 'out9.csv', 'out7.csv', 'out5.csv', 'out3.csv', 'out1.csv', 'out8.csv', 'out4.csv', 'out0.csv', 'out26.csv', 'out27.csv', 'out28.csv', 'out23.csv', 'out24.csv', 'out22.csv', 'out21.csv', 'out25.csv', 'out20.csv']
Input:labels/stopsign_original/out19.csv
Output:labels/stopsign/out19.csv
47,103,470,581,tops

['47,103,470,581,tops\n']
Traceback (most recent call last):
File "convert.py", line 78, in <module>
xmax = elems[1]
IndexError: list index out of range

上記のようなエラーが出てしまいます。

解決策を教えてください。
お願いします。

これだけでは足りないと思うので解決する為に必要な情報があったら教えてください。
環境はgooglecolabです。

python

1convert.pyのコード 2```# -*- coding: utf-8 -*- 3""" 4Created on Wed Dec 9 14:55:43 2015 5This script is to convert the txt annotation files to appropriate format needed by YOLO 6@author: Guanghan Ning 7Email: gnxr9@mail.missouri.edu 8""" 9 10import os 11from os import walk, getcwd 12from PIL import Image 13 14classes = ["stopsign"] 15 16def convert(size, box): 17 dw = 1./size[0] 18 dh = 1./size[1] 19 x = (box[0] + box[1])/2.0 20 y = (box[2] + box[3])/2.0 21 w = box[1] - box[0] 22 h = box[3] - box[2] 23 x = x*dw 24 w = w*dw 25 y = y*dh 26 h = h*dh 27 return (x,y,w,h) 28 29 30"""-------------------------------------------------------------------""" 31 32""" Configure Paths""" 33mypath = "labels/stopsign_original/" 34outpath = "labels/stopsign/" 35 36cls = "stopsign" 37if cls not in classes: 38 exit(0) 39cls_id = classes.index(cls) 40 41wd = getcwd() 42list_file = open('%s/%s_list.txt'%(wd, cls), 'w') 43 44""" Get input text file list """ 45txt_name_list = [] 46for (dirpath, dirnames, filenames) in walk(mypath): 47 txt_name_list.extend(filenames) 48 break 49print(txt_name_list) 50 51""" Process """ 52for txt_name in txt_name_list: 53 # txt_file = open("Labels/stop_sign/001.txt", "r") 54 55 """ Open input text files """ 56 txt_path = mypath + txt_name 57 print("Input:" + txt_path) 58 txt_file = open(txt_path, "r") 59 lines = txt_file.read().split('\r\n') #for ubuntu, use "\r\n" instead of "\n" 60 61 """ Open output text files """ 62 txt_outpath = outpath + txt_name 63 print("Output:" + txt_outpath) 64 txt_outfile = open(txt_outpath, "w") 65 66 67 """ Convert the data to YOLO format """ 68 ct = 0 69 for line in lines: 70 #print('lenth of line is: ') 71 #print(len(line)) 72 #print('\n') 73 if(len(line) >= 2): 74 ct = ct + 1 75 print(line + "\n") 76 elems = line.split(' ') 77 print(elems) 78 xmin = elems[0] 79 xmax = elems[1] 80 ymin = elems[2] 81 ymax = elems[3] 82 # 83 img_path = str('%s/images/%s/%s.JPEG'%(wd, cls, os.path.splitext(txt_name)[0])) 84 #t = magic.from_file(img_path) 85 #wh= re.search('(\d+) x (\d+)', t).groups() 86 im=Image.open(img_path) 87 w= int(im.size[0]) 88 h= int(im.size[1]) 89 #w = int(xmax) - int(xmin) 90 #h = int(ymax) - int(ymin) 91 # print(xmin) 92 print(w, h) 93 b = (float(xmin), float(xmax), float(ymin), float(ymax)) 94 bb = convert((w,h), b) 95 print(bb) 96 txt_outfile.write(str(cls_id) + " " + " ".join([str(a) for a in bb]) + '\n') 97 98 """ Save those images with bb into list""" 99 if(ct != 0): 100 list_file.write('%s/images/%s/%s.JPEG\n'%(wd, cls, os.path.splitext(txt_name)[0])) 101 102list_file.close()

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

Python

1if(len(line) >= 2): 2 ct = ct + 1 3 print(line + "\n") 4 elems = line.split(' ') 5 print(elems) 6 xmin = elems[0] 7 xmax = elems[1]

lineの内容がカンマ区切りであるのに、スペースで分割しようとして失敗しています。

投稿2018/12/13 10:30

kazto

総合スコア7196

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

buffalo

2018/12/13 11:11

ありがとうございます! 解決できました!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問