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

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

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

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

Python

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

Q&A

解決済

1回答

1731閲覧

Tensorflowでのcsv読み込みについて

eringi337

総合スコア16

CSV

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

Python

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

0グッド

1クリップ

投稿2019/10/16 06:46

下記のコードを用いてTensorflowで画像から変換したcsvのファイルを読み込みたいです。
Colaboratoryで実行しています。

import sys import tensorflow as tf def read_csv(csvfile): fname_queue = tf.train.string_input_producer(["/content/drive/magefiles.csv"]) reader = tf.TextLineReader() key, val = reader.read(fname_queue) fname, label = tf.decode_csv(val, [["aa"], [1]]) return read_img(fname) def read_img(fname): img_r = tf.read_file(fname) return tf.image.decode_image(img_r, channels=3) def main(): argv = sys.argv argc = len(argv) if (argc < 2): print('Usage: python %s csvfile' %argv[0]) quit() image = read_csv(argv[1]) sess = tf.Session() init = tf.initialize_all_variables() sess.run(init) tf.train.start_queue_runners(sess) x = sess.run(image) print(x) if __name__ == '__main__': main()

このコードを実行するとこのようなエラーが出ます。

--------------------------------------------------------------------------- InvalidArgumentError Traceback (most recent call last) /usr/local/lib/python3.6/dist-packages/tensorflow_core/python/client/session.py in _do_call(self, fn, *args) 1364 try: -> 1365 return fn(*args) 1366 except errors.OpError as e: 7 frames InvalidArgumentError: 2 root error(s) found. (0) Invalid argument: Quoted field has to end with quote followed by delim or end [[{{node DecodeCSV_6}}]] (1) Invalid argument: Quoted field has to end with quote followed by delim or end [[{{node DecodeCSV_6}}]] [[decode_image_5/cond_jpeg/DecodeJpeg/_113]] 0 successful operations. 0 derived errors ignored. During handling of the above exception, another exception occurred: InvalidArgumentError Traceback (most recent call last) /usr/local/lib/python3.6/dist-packages/tensorflow_core/python/client/session.py in _do_call(self, fn, *args) 1382 '\nsession_config.graph_options.rewrite_options.' 1383 'disable_meta_optimizer = True') -> 1384 raise type(e)(node_def, op, message) 1385 1386 def _extend_graph(self): InvalidArgumentError: 2 root error(s) found. (0) Invalid argument: Quoted field has to end with quote followed by delim or end [[node DecodeCSV_6 (defined at /usr/local/lib/python3.6/dist-packages/tensorflow_core/python/framework/ops.py:1748) ]] (1) Invalid argument: Quoted field has to end with quote followed by delim or end [[node DecodeCSV_6 (defined at /usr/local/lib/python3.6/dist-packages/tensorflow_core/python/framework/ops.py:1748) ]] [[decode_image_5/cond_jpeg/DecodeJpeg/_113]] 0 successful operations. 0 derived errors ignored.

引数が無効で,引用符の後にdelimかendを付けなければならないという事はわかるのですが,これに該当する部分がどこなのかわかりません。

もし解決方法を知っている方がいらっしゃればご教示願います。
また,csvからではなくてもTensorflowで画像ファイルを読み込む方法でも構いません。よろしくお願いいたします。

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

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

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

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

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

guest

回答1

0

ベストアンサー

画像はCSVや他の形式で扱うより、Numpy(OpenCV)の配列の方が分かりやすいですよね。
お試しください。


参照先ではNumpyに流し込むまでにPILを使っていますが、OpenCVでも行けると思います。

投稿2019/10/16 10:08

編集2019/10/16 10:10
退会済みユーザー

退会済みユーザー

総合スコア0

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

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

eringi337

2019/10/16 13:24

回答ありがとうございます。 配列へ変換してtf.read_fileで読み込むという形でいいのでしょうか?
eringi337

2019/10/16 18:19

解決しました。ありがとうございます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問