TensorFlow 2.0:不能同时进行一项以上的培训

时间:2019-12-04 01:08:24

标签: python tensorflow tensorflow2.0 tf.keras

我正在使用来自Tensorflow 2.0的tf.keras。 我想在不同的Jupyter笔记本中同时训练两个模型。 我可以使用tensorflow 1.14来做到这一点,但是在tensorflow 2.0中它不起作用。

每次尝试这样做都会导致以下错误:

InternalError                             Traceback (most recent call last)
<ipython-input-8-dd370f9046fc> in <module>
----> 1 predictor.train(2000,64)

<ipython-input-4-68b2bf23e56d> in train(self, num_epochs, batch)
     31         callbacks = [lossplot, checkpoint1,es] #tensorboard,
     32 
---> 33         self.model.fit(self.xtrain,self.ytrain, shuffle=True, epochs=num_epochs, batch_size=batch, callbacks=callbacks)
     34 
     35     def evaluate(self,xeval,yeval,df_eval,target,eval_mode='train',reps=5,scale=True):

C:\ProgramData\Miniconda3\envs\tf2\lib\site-packages\tensorflow_core\python\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, validation_freq, max_queue_size, workers, use_multiprocessing, **kwargs)
    726         max_queue_size=max_queue_size,
    727         workers=workers,
--> 728         use_multiprocessing=use_multiprocessing)
    729 
    730   def evaluate(self,

C:\ProgramData\Miniconda3\envs\tf2\lib\site-packages\tensorflow_core\python\keras\engine\training_arrays.py in fit(self, model, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_freq, **kwargs)
    672         validation_steps=validation_steps,
    673         validation_freq=validation_freq,
--> 674         steps_name='steps_per_epoch')
    675 
    676   def evaluate(self,

C:\ProgramData\Miniconda3\envs\tf2\lib\site-packages\tensorflow_core\python\keras\engine\training_arrays.py in model_iteration(model, inputs, targets, sample_weights, batch_size, epochs, verbose, callbacks, val_inputs, val_targets, val_sample_weights, shuffle, initial_epoch, steps_per_epoch, validation_steps, validation_freq, mode, validation_in_fit, prepared_feed_values_from_dataset, steps_name, **kwargs)
    391 
    392         # Get outputs.
--> 393         batch_outs = f(ins_batch)
    394         if not isinstance(batch_outs, list):
    395           batch_outs = [batch_outs]

C:\ProgramData\Miniconda3\envs\tf2\lib\site-packages\tensorflow_core\python\keras\backend.py in __call__(self, inputs)
   3738         value = math_ops.cast(value, tensor.dtype)
   3739       converted_inputs.append(value)
-> 3740     outputs = self._graph_fn(*converted_inputs)
   3741 
   3742     # EagerTensor.numpy() will often make a copy to ensure memory safety.

C:\ProgramData\Miniconda3\envs\tf2\lib\site-packages\tensorflow_core\python\eager\function.py in __call__(self, *args, **kwargs)
   1079       TypeError: For invalid positional/keyword argument combinations.
   1080     """
-> 1081     return self._call_impl(args, kwargs)
   1082 
   1083   def _call_impl(self, args, kwargs, cancellation_manager=None):

C:\ProgramData\Miniconda3\envs\tf2\lib\site-packages\tensorflow_core\python\eager\function.py in _call_impl(self, args, kwargs, cancellation_manager)
   1119       raise TypeError("Keyword arguments {} unknown. Expected {}.".format(
   1120           list(kwargs.keys()), list(self._arg_keywords)))
-> 1121     return self._call_flat(args, self.captured_inputs, cancellation_manager)
   1122 
   1123   def _filtered_call(self, args, kwargs):

C:\ProgramData\Miniconda3\envs\tf2\lib\site-packages\tensorflow_core\python\eager\function.py in _call_flat(self, args, captured_inputs, cancellation_manager)
   1222     if executing_eagerly:
   1223       flat_outputs = forward_function.call(
-> 1224           ctx, args, cancellation_manager=cancellation_manager)
   1225     else:
   1226       gradient_name = self._delayed_rewrite_functions.register()

C:\ProgramData\Miniconda3\envs\tf2\lib\site-packages\tensorflow_core\python\eager\function.py in call(self, ctx, args, cancellation_manager)
    509               inputs=args,
    510               attrs=("executor_type", executor_type, "config_proto", config),
--> 511               ctx=ctx)
    512         else:
    513           outputs = execute.execute_with_cancellation(

C:\ProgramData\Miniconda3\envs\tf2\lib\site-packages\tensorflow_core\python\eager\execute.py in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
     65     else:
     66       message = e.message
---> 67     six.raise_from(core._status_to_exception(e.code, message), None)
     68   except TypeError as e:
     69     keras_symbolic_tensors = [

C:\ProgramData\Miniconda3\envs\tf2\lib\site-packages\six.py in raise_from(value, from_value)

InternalError:  Blas GEMV launch failed:  m=147, n=64
     [[node model/dense/MatMul (defined at C:\ProgramData\Miniconda3\envs\tf2\lib\site-packages\tensorflow_core\python\framework\ops.py:1751) ]] [Op:__inference_keras_scratch_graph_5652]

Function call stack:
keras_scratch_graph

是否有一种变通办法可以同时训练两个或多个模型?

0 个答案:

没有答案