Code to reproduce the error (copied from https://tfhub.dev/google/tf2-preview/nnlm-en-dim128/1):
import tensorflow_hub as hub
embed = hub.load("https://tfhub.dev/google/tf2-preview/nnlm-en-dim128/1")
embeddings = embed(["cat is on the mat", "dog is in the fog"])
Re-run the last line again, or wrap the list input with tf.constant, seems to solve the issue.
I'm using Alpha preview of TF 2.0.
Problem confirmed.
This has been fixed in March 5th in https://github.com/tensorflow/tensorflow/commit/46ebf0267ad8af92bc7a7331b96ec742e00d296f#diff-fd05cc53efd6ecee89775b1fc1f0a4bb
The fix will be in the next 2.0 release, but for now you have to install from nightly builds.
E.g.
!pip install tf-nightly-2.0-preview
Instead of the "pip install tensorflow==2.0.0a0"
Thanks for the response. So for the current version, are the results obtained from wrapping the input with tf.constant workaround correct? I'm totally fine with an extra line of code if the results are correct.
Yes, I think passing a tf.constant will work just fine
I this actually fixed? I am hitting same errors but with 100 and 102.
396 raise ValueError(
397 "Arguments and signature arguments do not match: %s %s " %
--> 398 (len(args), len(list(self.signature.input_arg))))
399
400 function_call_options = ctx.function_call_options
ValueError: Arguments and signature arguments do not match: 100 102
Am on latest nightly 2.0.
Hello, I am having the same issue using tensorflow 2.0.0-alpha0 , getting the following error from a jupyter notebook:
ValueError Traceback (most recent call last)
2 tr = tf.constant(examples)
3 BATCH_SIZE = 32
----> 4 model.fit(tr, epochs=5, steps_per_epoch=math.ceil(len(train)/BATCH_SIZE))
~\Anaconda3\envs\thesis_tensorflow\lib\site-packages\tensorflow\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)
871 validation_steps=validation_steps,
872 validation_freq=validation_freq,
--> 873 steps_name='steps_per_epoch')
874
875 def evaluate(self,
~\Anaconda3\envs\thesis_tensorflow\lib\site-packages\tensorflow\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)
261 # ins can be callable in DistributionStrategy + eager case.
262 actual_inputs = ins() if callable(ins) else ins
--> 263 batch_outs = f(actual_inputs)
264 except errors.OutOfRangeError:
265 if is_dataset:
~\Anaconda3\envs\thesis_tensorflow\lib\site-packages\tensorflow\python\keras\backend.py in __call__(self, inputs)
3215 value = math_ops.cast(value, tensor.dtype)
3216 converted_inputs.append(value)
-> 3217 outputs = self._graph_fn(*converted_inputs)
3218 return nest.pack_sequence_as(self._outputs_structure,
3219 [x.numpy() for x in outputs])
~\Anaconda3\envs\thesis_tensorflow\lib\site-packages\tensorflow\python\eager\function.py in __call__(self, args, *kwargs)
556 raise TypeError("Keyword arguments {} unknown. Expected {}.".format(
557 list(kwargs.keys()), list(self._arg_keywords)))
--> 558 return self._call_flat(args)
559
560 def _filtered_call(self, args, kwargs):
~\Anaconda3\envs\thesis_tensorflow\lib\site-packages\tensorflow\python\eager\function.py in _call_flat(self, args)
625 # Only need to override the gradient in graph mode and when we have outputs.
626 if context.executing_eagerly() or not self.outputs:
--> 627 outputs = self._inference_function.call(ctx, args)
628 else:
629 self._register_gradient()
~\Anaconda3\envs\thesis_tensorflow\lib\site-packages\tensorflow\python\eager\function.py in call(self, ctx, args)
395 raise ValueError(
396 "Arguments and signature arguments do not match: %s %s " %
--> 397 (len(args), len(list(self.signature.input_arg))))
398
399 function_call_options = ctx.get_function_call_options()
ValueError: Arguments and signature arguments do not match: 27 29
I'm still seeing this issue with the latest version.. Any updates?
This is no longer an issue with the nightly build:
pip install tf-nightly-2.0-preview
It won't start working in alpha until we get a new release.
@vbardiovskyg I'm having same issue with tensorflow-gpu: '2.1.0'. Any solutions ?
ValueError: Arguments and signature arguments do not match. got: 37, expected: 39
Hi Ahmed, sorry but I could not reproduce this. I tried tensorflow-gpu==2.1.0 and tensorflow-gpu==2.2.0 and tensorflow==2.2.0.
Are you sure you are importing the correct tensorflow? A typical issue is that there are both tensorflow and tensorflow-gpu installed, and when doing import tensorflow, it is not clear which got imported.
@vbardiovskyg thanks for replying. I only use: tensorflow-gpu: 2.1.0 and keras 2.3.1 for building MLP model. (using import keras instead of import tensorflow.keras )
This is what I'm trying to do:
model.fit_generator(generator=batch_generator(X_train, y_train, divide_on, True), epochs=1,
steps_per_epoch=np_steps,
verbose=1)
def batch_generator(X, y, batch_size, shuffle):
number_of_batches = round(X.shape[0] / batch_size)
print(f'y.shape: {X.shape}')
print(f'X.shape[0]: {X.shape[0]}')
print(f'batch_size: {batch_size}')
print(f'number_of_batches: {number_of_batches}')
counter = 0
sample_index = np.arange(X.shape[0])
if shuffle:
np.random.shuffle(sample_index)
while True:
batch_index = sample_index[batch_size * counter:batch_size * (counter + 1)]
print(f'counter: {counter}')
print(f'batch_index: {batch_index}')
X_batch = X[batch_index, :].toarray()
y_batch = y[batch_index]
counter += 1
print(f'yielded X_batch shape: {X_batch.shape} where counter: {counter}')
print(f'yielded y_batch shape: {y_batch.shape} where counter: {counter}')
yield X_batch, y_batch
if counter == number_of_batches:
if shuffle:
np.random.shuffle(sample_index)
counter = 0
While the result is:
shape of x_train: (1407577, 207)
shape of x_valid: (74084, 207)
Epoch 1/1
y.shape: (1407577, 207)
X.shape[0]: 1407577
batch_size: 64
number_of_batches: 21993
counter: 0
batch_index: [ 55578 885043 826530 1085983 596906 990879 150577 916018 1283648
657662 22295 978107 1330422 1094582 1323311 1386819 1349709 361209
1314015 112607 1363984 179845 464715 474078 337839 1097602 1173681
910575 1113526 27510 647144 1081263 678677 567365 149537 936813
202732 727397 21943 563727 923775 661254 465769 383644 99391
918760 1152295 23548 511531 661704 590537 855781 654484 1008951
690456 414501 998788 97076 334435 57625 822775 125039 857771
1103476]
yielded X_batch shape: (64, 207) where counter: 1
yielded y_batch shape: (64, 1) where counter: 1
counter: 1
batch_index: [ 784817 248893 472646 1010253 1400872 522094 217448 1120737 844047
837030 1298761 768817 728090 799502 951408 1356634 365863 997856
752368 558098 732175 571739 1048726 536754 1315847 1032336 413975
366115 550960 976257 1116407 237934 386406 1160910 113013 163694
437774 372660 1164205 335589 223032 1364559 626345 1135905 396354
1120329 567954 1252556 763024 351094 445536 734038 1344405 239830
869035 728995 288278 238975 699285 1267507 131834 24448 233283
623641]
Traceback (most recent call last):
File "mlp.py", line 443, in <module>
yielded X_batch shape: (64, 207) where counter: 2
yielded y_batch shape: (64, 1) where counter: 2
main()
File "mlp.py", line 371, in main
model1 = run_model1(X_train, y_train, X_valid, y_valid)
File "mlp.py", line 255, in run_model1
verbose=1)
File "/path_to_project/venv/lib/python3.6/site-packages/keras/legacy/interfaces.py", line 91, in wrapper
return func(*args, **kwargs)
File "/path_to_project/venv/lib/python3.6/site-packages/keras/engine/training.py", line 1732, in fit_generator
initial_epoch=initial_epoch)
File "/path_to_project/venv/lib/python3.6/site-packages/keras/engine/training_generator.py", line 220, in fit_generator
reset_metrics=False)
File "/path_to_project/venv/lib/python3.6/site-packages/keras/engine/training.py", line 1514, in train_on_batch
outputs = self.train_function(ins)
File "/path_to_project/venv/lib/python3.6/site-packages/tensorflow_core/python/keras/backend.py", line 3727, in __call__
outputs = self._graph_fn(*converted_inputs)
File "/path_to_project/venv/lib/python3.6/site-packages/tensorflow_core/python/eager/function.py", line 1551, in __call__
return self._call_impl(args, kwargs)
File "/path_to_project/venv/lib/python3.6/site-packages/tensorflow_core/python/eager/function.py", line 1591, in _call_impl
return self._call_flat(args, self.captured_inputs, cancellation_manager)
File "/path_to_project/venv/lib/python3.6/site-packages/tensorflow_core/python/eager/function.py", line 1692, in _call_flat
ctx, args, cancellation_manager=cancellation_manager))
File "/path_to_project/venv/lib/python3.6/site-packages/tensorflow_core/python/eager/function.py", line 527, in call
(len(args), len(list(self.signature.input_arg))))
ValueError: Arguments and signature arguments do not match. got: 37, expected: 39
It fails in the second iteration of the loop.
@vbardiovskyg thanks for replying. I only use:
tensorflow-gpu: 2.1.0andkeras 2.3.1for building MLP model. (usingimport kerasinstead ofimport tensorflow.keras)This is what I'm trying to do:
model.fit_generator(generator=batch_generator(X_train, y_train, divide_on, True), epochs=1, steps_per_epoch=np_steps, verbose=1)def batch_generator(X, y, batch_size, shuffle): number_of_batches = round(X.shape[0] / batch_size) print(f'y.shape: {X.shape}') print(f'X.shape[0]: {X.shape[0]}') print(f'batch_size: {batch_size}') print(f'number_of_batches: {number_of_batches}') counter = 0 sample_index = np.arange(X.shape[0]) if shuffle: np.random.shuffle(sample_index) while True: batch_index = sample_index[batch_size * counter:batch_size * (counter + 1)] print(f'counter: {counter}') print(f'batch_index: {batch_index}') X_batch = X[batch_index, :].toarray() y_batch = y[batch_index] counter += 1 print(f'yielded X_batch shape: {X_batch.shape} where counter: {counter}') print(f'yielded y_batch shape: {y_batch.shape} where counter: {counter}') yield X_batch, y_batch if counter == number_of_batches: if shuffle: np.random.shuffle(sample_index) counter = 0While the result is:
shape of x_train: (1407577, 207) shape of x_valid: (74084, 207) Epoch 1/1 y.shape: (1407577, 207) X.shape[0]: 1407577 batch_size: 64 number_of_batches: 21993 counter: 0 batch_index: [ 55578 885043 826530 1085983 596906 990879 150577 916018 1283648 657662 22295 978107 1330422 1094582 1323311 1386819 1349709 361209 1314015 112607 1363984 179845 464715 474078 337839 1097602 1173681 910575 1113526 27510 647144 1081263 678677 567365 149537 936813 202732 727397 21943 563727 923775 661254 465769 383644 99391 918760 1152295 23548 511531 661704 590537 855781 654484 1008951 690456 414501 998788 97076 334435 57625 822775 125039 857771 1103476] yielded X_batch shape: (64, 207) where counter: 1 yielded y_batch shape: (64, 1) where counter: 1 counter: 1 batch_index: [ 784817 248893 472646 1010253 1400872 522094 217448 1120737 844047 837030 1298761 768817 728090 799502 951408 1356634 365863 997856 752368 558098 732175 571739 1048726 536754 1315847 1032336 413975 366115 550960 976257 1116407 237934 386406 1160910 113013 163694 437774 372660 1164205 335589 223032 1364559 626345 1135905 396354 1120329 567954 1252556 763024 351094 445536 734038 1344405 239830 869035 728995 288278 238975 699285 1267507 131834 24448 233283 623641] Traceback (most recent call last): File "mlp.py", line 443, in <module> yielded X_batch shape: (64, 207) where counter: 2 yielded y_batch shape: (64, 1) where counter: 2 main() File "mlp.py", line 371, in main model1 = run_model1(X_train, y_train, X_valid, y_valid) File "mlp.py", line 255, in run_model1 verbose=1) File "/path_to_project/venv/lib/python3.6/site-packages/keras/legacy/interfaces.py", line 91, in wrapper return func(*args, **kwargs) File "/path_to_project/venv/lib/python3.6/site-packages/keras/engine/training.py", line 1732, in fit_generator initial_epoch=initial_epoch) File "/path_to_project/venv/lib/python3.6/site-packages/keras/engine/training_generator.py", line 220, in fit_generator reset_metrics=False) File "/path_to_project/venv/lib/python3.6/site-packages/keras/engine/training.py", line 1514, in train_on_batch outputs = self.train_function(ins) File "/path_to_project/venv/lib/python3.6/site-packages/tensorflow_core/python/keras/backend.py", line 3727, in __call__ outputs = self._graph_fn(*converted_inputs) File "/path_to_project/venv/lib/python3.6/site-packages/tensorflow_core/python/eager/function.py", line 1551, in __call__ return self._call_impl(args, kwargs) File "/path_to_project/venv/lib/python3.6/site-packages/tensorflow_core/python/eager/function.py", line 1591, in _call_impl return self._call_flat(args, self.captured_inputs, cancellation_manager) File "/path_to_project/venv/lib/python3.6/site-packages/tensorflow_core/python/eager/function.py", line 1692, in _call_flat ctx, args, cancellation_manager=cancellation_manager)) File "/path_to_project/venv/lib/python3.6/site-packages/tensorflow_core/python/eager/function.py", line 527, in call (len(args), len(list(self.signature.input_arg)))) ValueError: Arguments and signature arguments do not match. got: 37, expected: 39It fails in the second iteration of the loop.
The problem solved after replacing import keras by import tensorflow.keras and making the necessary modifications
Most helpful comment
This has been fixed in March 5th in https://github.com/tensorflow/tensorflow/commit/46ebf0267ad8af92bc7a7331b96ec742e00d296f#diff-fd05cc53efd6ecee89775b1fc1f0a4bb
The fix will be in the next 2.0 release, but for now you have to install from nightly builds.