2017-08-28 41 views
0

コード:Keras InceptionV3はmodel.predict

from keras.applications import InceptionV3 
    model = InceptionV3(weights="imagenet") 
    shape = (None,image_size,image_size,num_channels) 
    x = tf.placeholder(tf.float32, shape=shape)  
    adv_x,grad_x = fgm(x, model, model.predict(x), y=y, targeted=True, eps=0, clip_min=-0.5, clip_max=0.5) 
    adv_,grad_ = batch_eval(sess, [x,y], [adv_x,grad_x], [inputs,targets], args={'batch_size': args['batch_size']}) 

    model.predict(x) 

エラー:

File "/u/.../env/lib/python3.5/site-packages/keras/engine/training.py", line 1594, in predict 
    batch_size=batch_size, verbose=verbose) 
    File "/u/.../env/lib/python3.5/site-packages/keras/engine/training.py", line 1208, in _predict_loop 
    batches = _make_batches(samples, batch_size) 
    File "/u/.../env/lib/python3.5/site-packages/keras/engine/training.py", line 364, in _make_batches 
    num_batches = int(np.ceil(size/float(batch_size))) 
TypeError: unsupported operand type(s) for /: 'Dimension' and 'float' 

私は、実際の画像にmodel.predictを使用しますが、tf.placeholdersまたはtf.variables上でこのエラーで終わることができます 誰でもこのエラーをデバッグする手助けはできますか?

答えて

0

Keras 'Model.predictは、入力データに対してnumpy配列が必要です。私は象徴的な攻撃がtensorflowに組み込まれている賢馬ハンスライブラリを、使用してい

predict(self, x, batch_size=None, verbose=0, steps=None) method of keras.engine.training.Model instance 
    Generates output predictions for the input samples. 

    Computation is done in batches. 

    # Arguments 
     x: The input data, as a Numpy array 
      (or list of Numpy arrays if the model has multiple outputs). 
     batch_size: Integer. If unspecified, it will default to 32. 
     verbose: Verbosity mode, 0 or 1. 
     steps: Total number of steps (batches of samples) 
      before declaring the prediction round finished. 
      Ignored with the default value of `None`. 

    # Returns 
     Numpy array(s) of predictions. 

    # Raises 
     ValueError: In case of mismatch between the provided 
      input data and the model's expectations, 
+0

:また、あなたのバッチサイズは、ドキュメントから32である場合を除き、batch_size値を含めることができます。上記の質問を編集しました。私は私自身のMNISTとCIFARシーケンシャルモデルを構築したので、これを実行できるはずです。このコードは実行可能です。なぜプレトレーニングされたモデルが違うのですか? –

関連する問題