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

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

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

Kerasは、TheanoやTensorFlow/CNTK対応のラッパーライブラリです。DeepLearningの数学的部分を短いコードでネットワークとして表現することが可能。DeepLearningの最新手法を迅速に試すことができます。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Q&A

1回答

2953閲覧

畳み込み層におけるエラー解決法(Python,keras)

TAKASHI_YAMADA

総合スコア12

Keras

Kerasは、TheanoやTensorFlow/CNTK対応のラッパーライブラリです。DeepLearningの数学的部分を短いコードでネットワークとして表現することが可能。DeepLearningの最新手法を迅速に試すことができます。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

0グッド

0クリップ

投稿2019/06/26 06:06

編集2019/06/26 08:50

前提・実現したいこと

Pythonで低解像度画像を高解像度化するモデルを生成しています。
2つの流れで生成された画像を1つに組み合わせて、畳み込みを行う際にエラーが発生しました。
入力画像のサイズは16×16のグレー画像で、出力では128×128にしたいです。
参考にした論文:"https://arxiv.org/pdf/1603.07235.pdf"
今年の春からプログラミングを始めた初心者です。質問内容以外にも指摘してくださるとありがたいです。
よろしくお願いします。

### 発生している問題・エラーメッセージ Layer conv2d_1 was called with an input that isn't a symbolic tensor. Received type: <class 'keras.layers.merge.Concatenate'>. Full input: [<keras.layers.merge.Concatenate object at 0x00000168E176FB70>]. All inputs to the layer should be tensors.

###Traceback

Traceback (most recent call last): File "c:\program files (x86)\microsoft visual studio\2017\community\common7\ide\extensions\microsoft\python\core\ptvsd_launcher.py", line 119, in <module> vspd.debug(filename, port_num, debug_id, debug_options, run_as) File "c:\program files (x86)\microsoft visual studio\2017\community\common7\ide\extensions\microsoft\python\core\Packages\ptvsd\debugger.py", line 37, in debug run(address, filename, *args, **kwargs) File "c:\program files (x86)\microsoft visual studio\2017\community\common7\ide\extensions\microsoft\python\core\Packages\ptvsd\_local.py", line 64, in run_file run(argv, addr, **kwargs) File "c:\program files (x86)\microsoft visual studio\2017\community\common7\ide\extensions\microsoft\python\core\Packages\ptvsd\_local.py", line 125, in _run _pydevd.main() File "c:\program files (x86)\microsoft visual studio\2017\community\common7\ide\extensions\microsoft\python\core\Packages\ptvsd\_vendored\pydevd\pydevd.py", line 1743, in main debugger.connect(host, port) File "c:\program files (x86)\microsoft visual studio\2017\community\common7\ide\extensions\microsoft\python\core\Packages\ptvsd\_vendored\pydevd\pydevd.py", line 1099, in run return self._exec(is_module, entry_point_fn, module_name, file, globals, locals) File "c:\program files (x86)\microsoft visual studio\2017\community\common7\ide\extensions\microsoft\python\core\Packages\ptvsd\_vendored\pydevd\pydevd.py", line 1106, in _exec pydev_imports.execfile(file, globals, locals) # execute the script File "c:\program files (x86)\microsoft visual studio\2017\community\common7\ide\extensions\microsoft\python\core\Packages\ptvsd\_vendored\pydevd\_pydev_imps\_pydev_execfile.py", line 25, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "F:\source\repos\GLN\GLN\GLN\GLN.py", line 99, in <module> model = network_gln() File "F:\source\repos\GLN\GLN\GLN\GLN.py", line 86, in network_gln ln = Conv2D(16, (5,5),strides=1, padding="same", activation="relu")(Add) File "C:\Users\MARUI\AppData\Local\conda\conda\envs\DeepLearning\lib\site-packages\keras\engine\base_layer.py", line 414, in __call__ self.assert_input_compatibility(inputs) File "C:\Users\MARUI\AppData\Local\conda\conda\envs\DeepLearning\lib\site-packages\keras\engine\base_layer.py", line 285, in assert_input_compatibility str(inputs) + '. All inputs to the layer ' ValueError: Layer conv2d_1 was called with an input that isn't a symbolic tensor. Received type: <class 'keras.layers.merge.Concatenate'>. Full input: [<keras.layers.merge.Concatenate object at 0x000002F0AFBF9D30>]. All inputs to the layer should be tensors.

###コード

Python

1import os 2import cv2 3import numpy as np 4from keras.layers import Input, Conv2D, MaxPooling2D, UpSampling2D, Add, BatchNormalization, Activation, Dense, Flatten, Concatenate 5from keras.models import Model 6import keras.optimizers as optimizers 7from tensorflow.python.keras import backend as K 8import matplotlib.pyplot as plt 9 10IMAGE_SIZE = 16 11 12""" 13前略 14""" 15def network_gln(): 16 input = Input(shape=(256,)) 17 input2 = Input(shape=(IMAGE_SIZE,IMAGE_SIZE,1)) 18 19 x1 = Dense(256, activation="relu")(input) 20 x1 = Dense(256, activation="relu")(x1) 21 x1 = Dense(256)(x1) 22 x1 = Dense(16384)(x1) 23 24 25 x2 = UpSampling2D((2,2))(input2) 26 x2 = UpSampling2D((2,2))(x2) 27 x2 = UpSampling2D((2,2))(x2) 28 29 Add = Concatenate([x1,x2]) 30 31 ln = Conv2D(16, (5,5),strides=1, padding="same", activation="relu")(Add) 32 ln = Conv2D(32, (7,7),strides=1, padding="same", activation="relu")(ln) 33 ln = Conv2D(64, (7,7),strides=1, padding="same", activation="relu")(ln) 34 ln = Conv2D(64, (7,7),strides=1, padding="same", activation="relu")(ln) 35 ln = Conv2D(64, (7,7),strides=1, padding="same", activation="relu")(ln) 36 ln = Conv2D(32, (7,7),strides=1, padding="same", activation="relu")(ln) 37 ln = Conv2D(16, (5,5),strides=1, padding="same", activation="relu")(ln) 38 output = Conv2D(1, (5,5),strides=1, padding="same")(ln) 39 40 model = Model(input, output) 41 42 return model 43 44model = network_gln()

試したこと

このエラーが出る前に、Upsamplingしたもの(x2)をDense(16384)層に通して同じ次元に直そうと試みましたが、同じエラーが出ました。
またx1の最後でnp.reshape(128,128)を試しましたがエラーがでて変形できませんでした。

環境

Windows10
Python3.6
Keras 2.2.4
Tensorflow-gpu 1.13.1
opencv 3.4.2

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

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

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

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

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

amahara_waya

2019/06/26 07:07

どの部分でエラーが発生しているか(Traceback)を追記してもらえると助かります。
TAKASHI_YAMADA

2019/06/26 07:23

すみません、追加しました。 よろしくお願いします。
amahara_waya

2019/06/26 07:32 編集

Tracebackを見る感じ、ln = Conv2D(16, (5,5),strides=1, padding="same", activation="relu")(x3)に問題があると思うのですが、質問者さんが提示したコードにx3についての定義が見当たりません(いきなりConv2Dの引数に使われている)。 x3について定義している箇所はありますか?
TAKASHI_YAMADA

2019/06/26 08:53

すみません、x3の部分をAddに直し忘れていました。それに伴い、Tracebackも修正しました。 申し訳ないですが、引き続きよろしくお願いします。
guest

回答1

0

以下のようにコードを書き換えてみたらどうでしょうか。

Add = Concatenate(axis=-1)([x1,x2])

参考記事:ValueError: input that isn't a symbolic tensor

投稿2019/06/27 00:01

amahara_waya

総合スコア1029

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問