spektral icon indicating copy to clipboard operation
spektral copied to clipboard

ValueError: Failed to convert a NumPy array to a Tensor (Unsupported numpy type: NPY_INT).

Open BetterWill opened this issue 3 years ago • 8 comments

Please,help :'( when I run the example citation_gat.py ,there's a mistake that bothers me. Traceback (most recent call last): File "D:/learn software/PyCharm 2020.1.1/project/No_23_spektral/2_GAT引文节点预测V1.0.py", line 22, in transforms=[LayerPreprocess(GATConv), AdjToSpTensor()]) File "D:\learn software\anaconda3\envs\spektral_2\lib\site-packages\spektral\datasets\citation.py", line 48, in init super().init(**kwargs) File "D:\learn software\anaconda3\envs\spektral_2\lib\site-packages\spektral\data\dataset.py", line 112, in init self.apply(t) File "D:\learn software\anaconda3\envs\spektral_2\lib\site-packages\spektral\data\dataset.py", line 125, in apply self.graphs[i] = transform(self.graphs[i]) File "D:\learn software\anaconda3\envs\spektral_2\lib\site-packages\spektral\transforms\adj_to_sp_tensor.py", line 10, in call graph.a = sp_matrix_to_sp_tensor(graph.a) File "D:\learn software\anaconda3\envs\spektral_2\lib\site-packages\spektral\layers\ops\sparse.py", line 19, in sp_matrix_to_sp_tensor dense_shape=x.shape File "D:\learn software\anaconda3\envs\spektral_2\lib\site-packages\tensorflow\python\framework\sparse_tensor.py", line 133, in init values = ops.convert_to_tensor(values, name="values") File "D:\learn software\anaconda3\envs\spektral_2\lib\site-packages\tensorflow\python\framework\ops.py", line 1499, in convert_to_tensor ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref) File "D:\learn software\anaconda3\envs\spektral_2\lib\site-packages\tensorflow\python\framework\tensor_conversion_registry.py", line 52, in _default_conversion_function return constant_op.constant(value, dtype, name=name) File "D:\learn software\anaconda3\envs\spektral_2\lib\site-packages\tensorflow\python\framework\constant_op.py", line 264, in constant allow_broadcast=True) File "D:\learn software\anaconda3\envs\spektral_2\lib\site-packages\tensorflow\python\framework\constant_op.py", line 275, in _constant_impl return _constant_eager_impl(ctx, value, dtype, shape, verify_shape) File "D:\learn software\anaconda3\envs\spektral_2\lib\site-packages\tensorflow\python\framework\constant_op.py", line 300, in _constant_eager_impl t = convert_to_eager_tensor(value, ctx, dtype) File "D:\learn software\anaconda3\envs\spektral_2\lib\site-packages\tensorflow\python\framework\constant_op.py", line 98, in convert_to_eager_tensor return ops.EagerTensor(value, ctx.device_name, dtype) ValueError: Failed to convert a NumPy array to a Tensor (Unsupported numpy type: NPY_INT).

python==3.7.0, tensorflow==2.3.1, spektral==1.0.0

BetterWill avatar Dec 03 '20 09:12 BetterWill

Hi,

can you provide a code example to reproduce this? I cannot reproduce the problem using the citation_gat.py script. I assume that you created a custom dataset, is that correct?

Cheers

danielegrattarola avatar Dec 03 '20 13:12 danielegrattarola

Hi, I also encounter similar error.

I run the same code from the example in : https://github.com/danielegrattarola/spektral/blob/master/examples/graph_prediction/qm9_ecc_batch.py

It would finally report " Unsupported numpy type: NPY_INT". I'm using numpy version 1.18.5. Not sure if there are other version issues.

Do you have any advice to overcome it?

below is the error message. Thank you.

InternalError Traceback (most recent call last) in 11 model.fit(loader_tr.load(), 12 steps_per_epoch=loader_tr.steps_per_epoch, ---> 13 epochs=epochs) 14 15 ################################################################################

~.conda\envs\tensorflow\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) 817 max_queue_size=max_queue_size, 818 workers=workers, --> 819 use_multiprocessing=use_multiprocessing) 820 821 def evaluate(self,

~.conda\envs\tensorflow\lib\site-packages\tensorflow_core\python\keras\engine\training_v2.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, max_queue_size, workers, use_multiprocessing, **kwargs) 340 mode=ModeKeys.TRAIN, 341 training_context=training_context, --> 342 total_epochs=epochs) 343 cbks.make_logs(model, epoch_logs, training_result, ModeKeys.TRAIN) 344

~.conda\envs\tensorflow\lib\site-packages\tensorflow_core\python\keras\engine\training_v2.py in run_one_epoch(model, iterator, execution_function, dataset_size, batch_size, strategy, steps_per_epoch, num_samples, mode, training_context, total_epochs) 126 step=step, mode=mode, size=current_batch_size) as batch_logs: 127 try: --> 128 batch_outs = execution_function(iterator) 129 except (StopIteration, errors.OutOfRangeError): 130 # TODO(kaftan): File bug about tf function and errors.OutOfRangeError?

~.conda\envs\tensorflow\lib\site-packages\tensorflow_core\python\keras\engine\training_v2_utils.py in execution_function(input_fn) 96 # numpy translates Tensors to values in Eager mode. 97 return nest.map_structure(_non_none_constant_value, ---> 98 distributed_function(input_fn)) 99 100 return execution_function

~.conda\envs\tensorflow\lib\site-packages\tensorflow_core\python\eager\def_function.py in call(self, *args, **kwds) 566 xla_context.Exit() 567 else: --> 568 result = self._call(*args, **kwds) 569 570 if tracing_count == self._get_tracing_count():

~.conda\envs\tensorflow\lib\site-packages\tensorflow_core\python\eager\def_function.py in _call(self, *args, **kwds) 630 # Lifting succeeded, so variables are initialized and we can run the 631 # stateless function. --> 632 return self._stateless_fn(*args, **kwds) 633 else: 634 canon_args, canon_kwds = \

~.conda\envs\tensorflow\lib\site-packages\tensorflow_core\python\eager\function.py in call(self, *args, **kwargs) 2361 with self._lock: 2362 graph_function, args, kwargs = self._maybe_define_function(args, kwargs) -> 2363 return graph_function._filtered_call(args, kwargs) # pylint: disable=protected-access 2364 2365 @property

~.conda\envs\tensorflow\lib\site-packages\tensorflow_core\python\eager\function.py in _filtered_call(self, args, kwargs) 1609 if isinstance(t, (ops.Tensor, 1610 resource_variable_ops.BaseResourceVariable))), -> 1611 self.captured_inputs) 1612 1613 def _call_flat(self, args, captured_inputs, cancellation_manager=None):

~.conda\envs\tensorflow\lib\site-packages\tensorflow_core\python\eager\function.py in _call_flat(self, args, captured_inputs, cancellation_manager) 1690 # No tape is watching; skip to running the function. 1691 return self._build_call_outputs(self._inference_function.call( -> 1692 ctx, args, cancellation_manager=cancellation_manager)) 1693 forward_backward = self._select_forward_and_backward_functions( 1694 args,

~.conda\envs\tensorflow\lib\site-packages\tensorflow_core\python\eager\function.py in call(self, ctx, args, cancellation_manager) 543 inputs=args, 544 attrs=("executor_type", executor_type, "config_proto", config), --> 545 ctx=ctx) 546 else: 547 outputs = execute.execute_with_cancellation(

~.conda\envs\tensorflow\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 = [

~.conda\envs\tensorflow\lib\site-packages\six.py in raise_from(value, from_value)

InternalError: 2 root error(s) found. (0) Internal: Unsupported numpy type: NPY_INT [[{{node PyFunc}}]] [[IteratorGetNext]] [[IteratorGetNext/_6]] (1) Internal: Unsupported numpy type: NPY_INT [[{{node PyFunc}}]] [[IteratorGetNext]] 0 successful operations. 0 derived errors ignored. [Op:__inference_distributed_function_2162]

Function call stack: distributed_function -> distributed_function

fylinhub avatar Dec 07 '20 00:12 fylinhub

Hi all,

so I've looked into the issue and found this: https://github.com/tensorflow/probability/issues/886

Then, I looked at both your stack traces and I noticed that both of you have backward slashes in your file paths :)

Unfortunately, this seems like a Tensorflow + Windows issue, not a Spektral one. In the example that I have linked above, they suggest to cast all inputs to a supported Numpy type (e.g., np.int32 instead of int) but I have no way of testing whether this is actually a solution for this case.

If you do find a solution, please let me know so that I can improve Windows support.

Cheers, Daniele

danielegrattarola avatar Dec 07 '20 08:12 danielegrattarola

I see; I'll try to get rid of this issue. Thank you for this possible solution.

fylinhub avatar Dec 07 '20 17:12 fylinhub

Hi,

can you provide a code example to reproduce this? I cannot reproduce the problem using the citation_gat.py script. I assume that you created a custom dataset, is that correct?

Cheers

I'm sorry I just saw your reply,The dataset which I used is "cora"。I didn't created a custom dataset. There is the coda: "# Load data dataset = Citation('cora', transforms=[LayerPreprocess(GATConv), AdjToSpTensor()]) " I'm using numpy version 1.18.5, too

BetterWill avatar Dec 09 '20 00:12 BetterWill

My roommate provides me a way to solve the problem, but not recommend unless you cannot find a better way. This problem might be caused by the some chaos between the C and TF, if you use the Windows. So you can start check the 'error' back to 'utils.py', at the 97th lines, replace the 'int32' to 'int64', done. Of course, if you can continue to check the 'c_api', maybe you will find the origin of the bug between the C and TF.

StereoCT avatar Jun 01 '21 00:06 StereoCT

@StereoCT is that utils.py file in Spektral?

danielegrattarola avatar Jun 01 '21 07:06 danielegrattarola

@StereoCT is that utils.py file in Spektral?

Nope, from my script, it's from 'neurite'. Generally it happens when we try to 'locs = [[tf.cast(f, 'int32') for f in loc0lst], [tf.cast(f, 'int32') for f in loc1]]', this command will convert the data to int32, and C will convert 32x to 64x, then the error happens. So I guess it must be the problem happened on 'from tensorflow.python import pywrap_tensorflow as c_api' if you check the error from back.

Here I only aim to the same problem I met but not from Spektral, maybe my method could be a direction to fix 'Tensorflow + Windows issue'.

StereoCT avatar Jun 01 '21 12:06 StereoCT