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

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

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

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

Q&A

解決済

1回答

1854閲覧

tensorflowのplaceholderの使い方

mothi5656

総合スコア27

Python

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

0グッド

0クリップ

投稿2020/11/13 10:23

上のコードをplaceholderを使って書き換えたいのですが、内容がよくわからないエラーが出ます。placeholderの使い方がこれで合っているかと、訂正すべきところがわからないのでおしえていただきたいです。

コード #課題4(プログラム1->変数に変更) import tensorflow as tf import numpy as np vector1=tf.Variable([1,2]) vector2=tf.Variable([2,1]) matrix1=tf.Variable([[1,2],[3,4]]) matrix2=tf.Variable([[3,4],[1,2]]) add1=tf.add(vector1,vector2) add2=tf.add(matrix1,matrix2) sess=tf.Session() sess.run(tf.global_variables_initializer()) print("add vector\t:\n",sess.run(add1)) print("add matrix\t:\n",sess.run(add2)) sess.close()
コード #課題4(プログラム1->プレースホルダーに変更) import tensorflow as tf import numpy as np vector1=tf.placeholder(tf.int32,[None,None]) vector2=tf.placeholder(tf.int32,[None,None]) matrix1=tf.placeholder(tf.int32,[[None,None],[None,None]]) matrix2=tf.placeholder(tf.int32,[[None,None],[None,None]]) add1=tf.add(vector1,vector2) add2=tf.add(matrix1,matrix2) sess=tf.Session() print("add vector\t:\n",sess.run(add1,feed_dict={vector1:[1,2],vector2:[2,1]})) print("add matrix\t:\n",sess.run(add2,feed_dict={matrix1:[[1,2],[3,4]],matrix2:[[3,4],[1,2]]})) sess.close()

エラー内容

TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'

During handling of the above exception, another exception occurred:

TypeError Traceback (most recent call last)
/tensorflow-1.15.2/python3.6/tensorflow_core/python/eager/execute.py in make_shape(v, arg_name)
206 shape = tensor_shape.as_shape(v)
207 except TypeError as e:
--> 208 raise TypeError("Error converting %s to a TensorShape: %s." % (arg_name, e))
209 except ValueError as e:
210 raise ValueError("Error converting %s to a TensorShape: %s." % (arg_name,

TypeError: Error converting shape to a TensorShape: int() argument must be a string, a bytes-like object or a number, not 'list'.

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

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

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

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

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

guest

回答1

0

ベストアンサー

tf.placeholderでテンソルを受け取るようにするには、shapeで型を指定してみてください。

vector1=tf.placeholder(tf.int32, shape=(2, ), name='vector1')
vector2=tf.placeholder(tf.int32, shape=(2, ), name='vector2')
matrix1=tf.placeholder(tf.int32, shape=(None, 2), name='matrix1')
matrix2=tf.placeholder(tf.int32, shape=(None, 2), name='matrix2')

投稿2020/11/13 17:27

technocore

総合スコア7225

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問