我试图运行这个Kaggle Jupyter Notebook的Python代码,遇到以下错误:
---------------------------------------------------------------------------
InternalError Traceback (most recent call last)
<ipython-input-40-be0fb0b18f3a> in <module>
1 #Defining Neural Network
----> 2 model = Sequential()
3 #Non-trainable embeddidng layer
4 model.add(Embedding(max_features, output_dim=embed_size, weights=[embedding_matrix], input_length=maxlen, trainable=False))
5 #LSTM
c:userskimappdatalocalprogramspythonpython38libsite-packagestensorflowpythontrainingtrackingbase.py in _method_wrapper(self, *args, **kwargs)
528 self._self_setattr_tracking = False # pylint: disable=protected-access
529 try:
--> 530 result = method(self, *args, **kwargs)
531 finally:
532 self._self_setattr_tracking = previous_value # pylint: disable=protected-access
c:userskimappdatalocalprogramspythonpython38libsite-packageskerasenginesequential.py in __init__(self, layers, name)
105 """
106 # Skip the init in FunctionalModel since model doesn't have input/output yet
--> 107 super(functional.Functional, self).__init__( # pylint: disable=bad-super-call
108 name=name, autocast=False)
109 base_layer.keras_api_gauge.get_cell('Sequential').set(True)
c:userskimappdatalocalprogramspythonpython38libsite-packagestensorflowpythontrainingtrackingbase.py in _method_wrapper(self, *args, **kwargs)
528 self._self_setattr_tracking = False # pylint: disable=protected-access
529 try:
--> 530 result = method(self, *args, **kwargs)
531 finally:
532 self._self_setattr_tracking = previous_value # pylint: disable=protected-access
c:userskimappdatalocalprogramspythonpython38libsite-packageskerasenginetraining.py in __init__(self, *args, **kwargs)
287 self._steps_per_execution = None
288
--> 289 self._init_batch_counters()
290 self._base_model_initialized = True
291
c:userskimappdatalocalprogramspythonpython38libsite-packagestensorflowpythontrainingtrackingbase.py in _method_wrapper(self, *args, **kwargs)
528 self._self_setattr_tracking = False # pylint: disable=protected-access
529 try:
--> 530 result = method(self, *args, **kwargs)
531 finally:
532 self._self_setattr_tracking = previous_value # pylint: disable=protected-access
c:userskimappdatalocalprogramspythonpython38libsite-packageskerasenginetraining.py in _init_batch_counters(self)
295 # `evaluate`, and `predict`.
296 agg = tf.VariableAggregation.ONLY_FIRST_REPLICA
--> 297 self._train_counter = tf.Variable(0, dtype='int64', aggregation=agg)
298 self._test_counter = tf.Variable(0, dtype='int64', aggregation=agg)
299 self._predict_counter = tf.Variable(
c:userskimappdatalocalprogramspythonpython38libsite-packagestensorflowpythonopsvariables.py in __call__(cls, *args, **kwargs)
266 return cls._variable_v1_call(*args, **kwargs)
267 elif cls is Variable:
--> 268 return cls._variable_v2_call(*args, **kwargs)
269 else:
270 return super(VariableMetaclass, cls).__call__(*args, **kwargs)
c:userskimappdatalocalprogramspythonpython38libsite-packagestensorflowpythonopsvariables.py in _variable_v2_call(cls, initial_value, trainable, validate_shape, caching_device, name, variable_def, dtype, import_scope, constraint, synchronization, aggregation, shape)
248 if aggregation is None:
249 aggregation = VariableAggregation.NONE
--> 250 return previous_getter(
251 initial_value=initial_value,
252 trainable=trainable,
c:userskimappdatalocalprogramspythonpython38libsite-packagestensorflowpythonopsvariables.py in <lambda>(**kws)
241 shape=None):
242 """Call on Variable class. Useful to force the signature."""
--> 243 previous_getter = lambda **kws: default_variable_creator_v2(None, **kws)
244 for _, getter in ops.get_default_graph()._variable_creator_stack: # pylint: disable=protected-access
245 previous_getter = _make_getter(getter, previous_getter)
c:userskimappdatalocalprogramspythonpython38libsite-packagestensorflowpythonopsvariable_scope.py in default_variable_creator_v2(next_creator, **kwargs)
2660 shape = kwargs.get("shape", None)
2661
-> 2662 return resource_variable_ops.ResourceVariable(
2663 initial_value=initial_value,
2664 trainable=trainable,
c:userskimappdatalocalprogramspythonpython38libsite-packagestensorflowpythonopsvariables.py in __call__(cls, *args, **kwargs)
268 return cls._variable_v2_call(*args, **kwargs)
269 else:
--> 270 return super(VariableMetaclass, cls).__call__(*args, **kwargs)
271
272
c:userskimappdatalocalprogramspythonpython38libsite-packagestensorflowpythonopsresource_variable_ops.py in __init__(self, initial_value, trainable, collections, validate_shape, caching_device, name, dtype, variable_def, import_scope, constraint, distribute_strategy, synchronization, aggregation, shape)
1600 self._init_from_proto(variable_def, import_scope=import_scope)
1601 else:
-> 1602 self._init_from_args(
1603 initial_value=initial_value,
1604 trainable=trainable,
c:userskimappdatalocalprogramspythonpython38libsite-packagestensorflowpythonopsresource_variable_ops.py in _init_from_args(self, initial_value, trainable, collections, caching_device, name, dtype, constraint, synchronization, aggregation, distribute_strategy, shape)
1743 self._update_uid = initial_value.checkpoint_position.restore_uid
1744 initial_value = initial_value.wrapped_value
-> 1745 initial_value = ops.convert_to_tensor(initial_value,
1746 name="initial_value",
1747 dtype=dtype)
c:userskimappdatalocalprogramspythonpython38libsite-packagestensorflowpythonprofilertrace.py in wrapped(*args, **kwargs)
161 with Trace(trace_name, **trace_kwargs):
162 return func(*args, **kwargs)
--> 163 return func(*args, **kwargs)
164
165 return wrapped
c:userskimappdatalocalprogramspythonpython38libsite-packagestensorflowpythonframeworkops.py in convert_to_tensor(value, dtype, name, as_ref, preferred_dtype, dtype_hint, ctx, accepted_result_types)
1564
1565 if ret is None:
-> 1566 ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
1567
1568 if ret is NotImplemented:
c:userskimappdatalocalprogramspythonpython38libsite-packagestensorflowpythonframeworktensor_conversion_registry.py in _default_conversion_function(***failed resolving arguments***)
50 def _default_conversion_function(value, dtype, name, as_ref):
51 del as_ref # Unused.
---> 52 return constant_op.constant(value, dtype, name=name)
53
54
c:userskimappdatalocalprogramspythonpython38libsite-packagestensorflowpythonframeworkconstant_op.py in constant(value, dtype, shape, name)
269 ValueError: if called on a symbolic tensor.
270 """
--> 271 return _constant_impl(value, dtype, shape, name, verify_shape=False,
272 allow_broadcast=True)
273
c:userskimappdatalocalprogramspythonpython38libsite-packagestensorflowpythonframeworkconstant_op.py in _constant_impl(value, dtype, shape, name, verify_shape, allow_broadcast)
281 with trace.Trace("tf.constant"):
282 return _constant_eager_impl(ctx, value, dtype, shape, verify_shape)
--> 283 return _constant_eager_impl(ctx, value, dtype, shape, verify_shape)
284
285 g = ops.get_default_graph()
c:userskimappdatalocalprogramspythonpython38libsite-packagestensorflowpythonframeworkconstant_op.py in _constant_eager_impl(ctx, value, dtype, shape, verify_shape)
306 def _constant_eager_impl(ctx, value, dtype, shape, verify_shape):
307 """Creates a constant on the current device."""
--> 308 t = convert_to_eager_tensor(value, ctx, dtype)
309 if shape is None:
310 return t
c:userskimappdatalocalprogramspythonpython38libsite-packagestensorflowpythonframeworkconstant_op.py in convert_to_eager_tensor(value, ctx, dtype)
103 except AttributeError:
104 dtype = dtypes.as_dtype(dtype).as_datatype_enum
--> 105 ctx.ensure_initialized()
106 return ops.EagerTensor(value, ctx.device_name, dtype)
107
c:userskimappdatalocalprogramspythonpython38libsite-packagestensorflowpythoneagercontext.py in ensure_initialized(self)
534 opts = pywrap_tfe.TFE_NewContextOptions()
535 try:
--> 536 config_str = self.config.SerializeToString()
537 pywrap_tfe.TFE_ContextOptionsSetConfig(opts, config_str)
538 if self._device_policy is not None:
c:userskimappdatalocalprogramspythonpython38libsite-packagestensorflowpythoneagercontext.py in config(self)
962 """Return the ConfigProto with all runtime deltas applied."""
963 # Ensure physical devices have been discovered and config has been imported
--> 964 self._initialize_physical_devices()
965
966 config = config_pb2.ConfigProto()
c:userskimappdatalocalprogramspythonpython38libsite-packagestensorflowpythoneagercontext.py in _initialize_physical_devices(self, reinitialize)
1291 return
1292
-> 1293 devs = pywrap_tfe.TF_ListPhysicalDevices()
1294 self._physical_devices = [
1295 PhysicalDevice(name=d.decode(), device_type=d.decode().split(":")[1])
InternalError: Cannot dlopen all CUDA libraries.
如何解决?
好的,所以我尝试了一些事情,安装tensorflow-gpu后,它工作了。也许它也可以帮助别人解决这个问题:
pip install tensorflow-gpu