2017-04-13 18 views
0

が定義されていない私はthis codeを実行しようとしますが、次のエラーを取得しています:とValueError:「フラット化」への入力の形状が完全に

Using TensorFlow backend. 
E c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\tensorflow\core\framework\op_kernel.cc:943] OpKernel ('op: "BestSplits" device_type: "CPU"') for unknown op: BestSplits 
E c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\tensorflow\core\framework\op_kernel.cc:943] OpKernel ('op: "CountExtremelyRandomStats" device_type: "CPU"') for unknown op: CountExtremelyRandomStats 
E c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\tensorflow\core\framework\op_kernel.cc:943] OpKernel ('op: "FinishedNodes" device_type: "CPU"') for unknown op: FinishedNodes 
E c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\tensorflow\core\framework\op_kernel.cc:943] OpKernel ('op: "GrowTree" device_type: "CPU"') for unknown op: GrowTree 
E c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\tensorflow\core\framework\op_kernel.cc:943] OpKernel ('op: "ReinterpretStringToFloat" device_type: "CPU"') for unknown op: ReinterpretStringToFloat 
E c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\tensorflow\core\framework\op_kernel.cc:943] OpKernel ('op: "SampleInputs" device_type: "CPU"') for unknown op: SampleInputs 
E c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\tensorflow\core\framework\op_kernel.cc:943] OpKernel ('op: "ScatterAddNdim" device_type: "CPU"') for unknown op: ScatterAddNdim 
E c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\tensorflow\core\framework\op_kernel.cc:943] OpKernel ('op: "TopNInsert" device_type: "CPU"') for unknown op: TopNInsert 
E c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\tensorflow\core\framework\op_kernel.cc:943] OpKernel ('op: "TopNRemove" device_type: "CPU"') for unknown op: TopNRemove 
E c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\tensorflow\core\framework\op_kernel.cc:943] OpKernel ('op: "TreePredictions" device_type: "CPU"') for unknown op: TreePredictions 
E c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\tensorflow\core\framework\op_kernel.cc:943] OpKernel ('op: "UpdateFertileSlots" device_type: "CPU"') for unknown op: UpdateFertileSlots 
Model loaded. 
Traceback (most recent call last): 
    File "classifier_from_little_data_script_3.py", line 64, in <module> 
    top_model.add(Flatten(input_shape=model.output_shape[1:])) 
    File "C:\Python35\lib\site-packages\keras\models.py", line 430, in add 
    layer(x) 
    File "C:\Python35\lib\site-packages\keras\engine\topology.py", line 583, in __call__ 
    output_shape = self.compute_output_shape(input_shape) 
    File "C:\Python35\lib\site-packages\keras\layers\core.py", line 488, in compute_output_shape 
    '(got ' + str(input_shape[1:]) + '. ' 
ValueError: The shape of the input to "Flatten" is not fully defined (got (None, None, 512). Make sure to pass a complete "input_shape" or "batch_input_shape" argument to the first layer in your model. 

どのように私はこの問題を解決することができますか?

ありがとうございました。

+1

あなたはhttps://gist.github.com/fchollet/7eb39b44eb9e16e59632d25fb3119975#gistcomment-([この修正]を試してみました2031679)を同じページから削除しますか? – umutto

+1

はい、それが問題を解決しました。どうもありがとう。 – Simplicity

答えて

0

@のumuttoさんのコメントに基づいて、これらの問題を解決し、変更した:他の誰かが同様の問題に直面している、そして問題のエラーがスローされた理由を不思議に思っているだけの場合には、私は意志

input_tensor = Input(shape=(150,150,3)) 
# build the VGG16 network 
model = applications.VGG16(weights='imagenet', include_top=False, input_tensor=input_tensor) 
3

@Simplicity's answerに詳細を追加してください:

keras documentationに記載されているように、Kerasにはこの記事の時点で2つのバックエンドのTheanoとTensorflowがあります。 TheanoとTensorflowのデータ/画像は、次元の順序が異なります。次のようにこの順序は以下のとおりです。

TensorFlow: [batch, width,height, channels]

Theano: [batch,channels, width, height]

あなたはどちらかにしている、(OPの場合のように)Tensorflowの順序をつもりを使用している場合:

  1. はあなたにkeras.json設定を、これを指定しますファイル(Ubuntuの~/.keras/keras.jsonにあります)。 Theanoを使用して実行するにはたとえば、あなたkeras.json設定ファイルには、次の行に置く:

    "image_dim_ordering": "th" 
    
    "backend": "theano" 
    
  2. を例えば、あなたのコードで使用される、関連するバックエンドを指定します。

    from keras import backend as K 
    K.set_image_dim_ordering('th') 
    

OPはTensorflowを使用しているので、データが[batch, width, height, channels]の形式であることを確認する必要があるため、入力テンソルを次のように変更する必要があります。

input_tensor = Input(shape=(150,150,3)) 

モデルとして:

model = applications.VGG16(weights='imagenet', include_top=False, input_tensor=input_tensor) 

としてOPは、入力テンソルが定義されなければならないTheanoバックエンドを使用していた:チャネルが最初であることを

input_tensor = Input(shape=(3, 150, 150)) 

-Noticeこの場合の議論。

とモデルと同じように定義される:ちょうど繰り返すために

model = applications.VGG16(weights='imagenet', include_top=False, input_tensor=input_tensor) 

。私はシンプリシティの答えがなぜ彼/彼女のために働いたのかを明確にしています。

私はこれが誰かを助けることを願っています:)。

出典:

関連する問題