0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[tensorflow]tf.nn.conv2d()のfiltersにはtensorを与える.

Posted at

備忘録です.
tf.nn.conv2d()の引数filtersにはtensorとして定義したkernelを与えましょう.

##悪い例

conv = tf.nn.conv2d(
                input=image,
                filters=[8,8,64,128],
                padding="VALID",
                data_format="NHWC"
            )

公式ドキュメントを見ればわかるが,filtersにはtensorを与える.上のようにkernelのshapeを与えてはいけない(気持ちはわかる).
ちなみに上記のコードだとこんなエラーが出る.

ValueError: Shape must be rank 4 but is rank 1 for 'Conv2D_1' (op: 'Conv2D') with input shapes: [?,28,28,64], [4].

##動く例

fil = tf.get_variable('weights', [8,8,64,128], dtype=tf.float32)
conv = tf.nn.conv2d(
                input=image
                filters=fil,
                padding="VALID",
                data_format="NHWC"
            )

kernel(fil)をtensorとして定義して,filtersにはそのtensorを与える.

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?