深度学习无法运行model.fit函数

时间:2018-12-03 12:16:52

标签: python keras deep-learning artificial-intelligence

我正在使用Cifar-10数据集,并且试图通过使用keras库进行转移学习。 我的代码在这里-https://github.com/YanaNeykova/Cifar-10 在运行

model.fit(X_train, y_train, batch_size=32, epochs=10,
         verbose=1, callbacks=[checkpointer],validation_split=0.2, shuffle=True)

我收到一个错误(在文件中可见),因此我无法继续进行。 我还尝试了另外从keras导入模型函数,但是我再次得到了相同的结果-无法识别函数模型。 有人可以建议我如何进行吗? 提前非常感谢!

错误

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-11-977cb2a1e5d6> in <module>()
      1 model.fit(X_train, y_train, batch_size=32, epochs=10,
----> 2          verbose=1, callbacks=[checkpointer],validation_split=0.2, shuffle=True)

/usr/local/lib/python3.6/dist-packages/keras/engine/training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, **kwargs)
   1008         else:
   1009             ins = x + y + sample_weights
-> 1010         self._make_train_function()
   1011         f = self.train_function
   1012 

/usr/local/lib/python3.6/dist-packages/keras/engine/training.py in _make_train_function(self)
    517                     updates=updates,
    518                     name='train_function',
--> 519                     **self._function_kwargs)
    520 
    521     def _make_test_function(self):

/usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py in function(inputs, outputs, updates, **kwargs)
   2742                 msg = 'Invalid argument "%s" passed to K.function with TensorFlow backend' % key
   2743                 raise ValueError(msg)
-> 2744     return Function(inputs, outputs, updates=updates, **kwargs)
   2745 
   2746 

/usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py in __init__(self, inputs, outputs, updates, name, **session_kwargs)
   2573             raise ValueError('Some keys in session_kwargs are not '
   2574                              'supported at this '
-> 2575                              'time: %s', session_kwargs.keys())
   2576         self._callable_fn = None
   2577         self._feed_arrays = None

ValueError: ('Some keys in session_kwargs are not supported at this time: %s', dict_keys(['metric']))

2 个答案:

答案 0 :(得分:1)

You have a typo error, try replaceing metric with metrics

Also you should correct loss binary_crossentropy to caegorical_crossentropy

model.compile(loss='caegorical_crossentropy', optimizer='adam',
         metrics=['accuracy'])

答案 1 :(得分:0)

You are using metric keyword argument that seems to be unsupported in the following line:

model.compile(loss='binary_crossentropy', optimizer='adam',
             metric=['accuracy'])

Try to remove it and see if it works. It may be unsupported in your model.

Also, I have noticed that you may have a typo in the name of the loss function loss='caegorical_crossentropy'... but I guess that is another issue.