tensorflow / probability

Probabilistic reasoning and statistical analysis in TensorFlow
https://www.tensorflow.org/probability/
Apache License 2.0
4.26k stars 1.1k forks source link

Python 3 + TF2 - TypeError: __init__() got an unexpected keyword argument 'values' #322

Closed lc0 closed 5 years ago

lc0 commented 5 years ago

I was testing a terrific example by @jvdillon and unfortunately it failed on my for TF2 and python3.6(default version for python3 env on colab)

code

encoder = tfk.Sequential([
    tfkl.InputLayer(input_shape=input_shape),
    tfkl.Lambda(lambda x: tf.cast(x, tf.float32) - 0.5),
    tfkl.Conv2D(base_depth, 5, strides=1,
                padding='same', activation=tf.nn.leaky_relu),
    tfkl.Conv2D(base_depth, 5, strides=2,
                padding='same', activation=tf.nn.leaky_relu),
    tfkl.Conv2D(2 * base_depth, 5, strides=1,
                padding='same', activation=tf.nn.leaky_relu),
    tfkl.Conv2D(2 * base_depth, 5, strides=2,
                padding='same', activation=tf.nn.leaky_relu),
    tfkl.Conv2D(4 * encoded_size, 7, strides=1,
                padding='valid', activation=tf.nn.leaky_relu),
    tfkl.Flatten(),
    tfkl.Dense(tfpl.MultivariateNormalTriL.params_size(encoded_size),
               activation=None),
    tfpl.MultivariateNormalTriL(
        encoded_size,
        activity_regularizer=tfpl.KLDivergenceRegularizer(prior)),
])

And error message

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-12-f6047244903c> in <module>()
     17     tfpl.MultivariateNormalTriL(
     18         encoded_size,
---> 19         activity_regularizer=tfpl.KLDivergenceRegularizer(prior)),
     20 ])

/usr/local/lib/python3.6/dist-packages/tensorflow/python/training/tracking/base.py in _method_wrapper(self, *args, **kwargs)
    454     self._setattr_tracking = False  # pylint: disable=protected-access
    455     try:
--> 456       result = method(self, *args, **kwargs)
    457     finally:
    458       self._setattr_tracking = previous_value  # pylint: disable=protected-access

/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/sequential.py in __init__(self, layers, name)
    106     if layers:
    107       for layer in layers:
--> 108         self.add(layer)
    109 
    110   @property

/usr/local/lib/python3.6/dist-packages/tensorflow/python/training/tracking/base.py in _method_wrapper(self, *args, **kwargs)
    454     self._setattr_tracking = False  # pylint: disable=protected-access
    455     try:
--> 456       result = method(self, *args, **kwargs)
    457     finally:
    458       self._setattr_tracking = previous_value  # pylint: disable=protected-access

/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/sequential.py in add(self, layer)
    185       # If the model is being built continuously on top of an input layer:
    186       # refresh its output.
--> 187       output_tensor = layer(self.outputs[0])
    188       if isinstance(output_tensor, list):
    189         raise TypeError('All layers in a Sequential model '

/usr/local/lib/python3.6/dist-packages/tensorflow_probability/python/layers/distribution_layer.py in __call__(self, inputs, *args, **kwargs)
    168     self._enter_dunder_call = True
    169     distribution, _ = super(DistributionLambda, self).__call__(
--> 170         inputs, *args, **kwargs)
    171     self._enter_dunder_call = False
    172     return distribution

/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/base_layer.py in __call__(self, inputs, *args, **kwargs)
    604                       base_layer_utils.AutoAddUpdates(self,
    605                                                       inputs)) as auto_updater:
--> 606                 outputs = self.call(inputs, *args, **kwargs)
    607                 auto_updater.set_outputs(outputs)
    608 

/usr/local/lib/python3.6/dist-packages/tensorflow_probability/python/layers/distribution_layer.py in call(self, inputs, *args, **kwargs)
    174   def call(self, inputs, *args, **kwargs):
    175     distribution, value = super(DistributionLambda, self).call(
--> 176         inputs, *args, **kwargs)
    177     if self._enter_dunder_call:
    178       # Its critical to return both distribution and concretization

/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/layers/core.py in call(self, inputs, mask)
    737     if generic_utils.has_arg(self.function, 'mask'):
    738       arguments['mask'] = mask
--> 739     return self.function(inputs, **arguments)
    740 
    741   def compute_mask(self, inputs, mask=None):

/usr/local/lib/python3.6/dist-packages/tensorflow_probability/python/layers/distribution_layer.py in _fn(*fargs, **fkwargs)
    145       """Wraps `make_distribution_fn` to return both dist and concrete value."""
    146       distribution = dtc._TensorCoercible(  # pylint: disable=protected-access
--> 147           distribution=make_distribution_fn(*fargs, **fkwargs),
    148           convert_to_tensor_fn=convert_to_tensor_fn)
    149       value = tf.convert_to_tensor(value=distribution)

/usr/local/lib/python3.6/dist-packages/tensorflow_probability/python/layers/distribution_layer.py in <lambda>(t)
    262     """
    263     super(MultivariateNormalTriL, self).__init__(
--> 264         lambda t: type(self).new(t, event_size, validate_args),
    265         convert_to_tensor_fn,
    266         **kwargs)

/usr/local/lib/python3.6/dist-packages/tensorflow_probability/python/layers/distribution_layer.py in new(params, event_size, validate_args, name)
    274       scale_tril = tfb.ScaleTriL(
    275           diag_shift=np.array(1e-5, params.dtype.as_numpy_dtype()),
--> 276           validate_args=validate_args)
    277       return tfd.MultivariateNormalTriL(
    278           loc=params[..., :event_size],

/usr/local/lib/python3.6/dist-packages/tensorflow_probability/python/bijectors/scale_tril.py in __init__(self, diag_bijector, diag_shift, validate_args, name)
    110             value=diag_shift, dtype=diag_bijector.dtype, name="diag_shift")
    111         diag_bijector = chain.Chain([
--> 112             affine_scalar.AffineScalar(shift=diag_shift),
    113             diag_bijector
    114         ])

/usr/local/lib/python3.6/dist-packages/tensorflow_probability/python/bijectors/affine_scalar.py in __init__(self, shift, scale, validate_args, name)
     81     self._validate_args = validate_args
     82 
---> 83     with self._name_scope("init", values=[scale, shift]):
     84       self._shift = shift
     85       self._scale = scale

/usr/lib/python3.6/contextlib.py in __enter__(self)
     79     def __enter__(self):
     80         try:
---> 81             return next(self.gen)
     82         except StopIteration:
     83             raise RuntimeError("generator didn't yield") from None

/usr/local/lib/python3.6/dist-packages/tensorflow_probability/python/bijectors/bijector.py in _name_scope(self, name, values)
   1210 
   1211   def _cache_by_x(self, mapping):
-> 1212     """Helper which stores new mapping info in the forward dict."""
   1213     # Merging from lookup is an added check that we're not overwriting anything
   1214     # which is not None.

TypeError: __init__() got an unexpected keyword argument 'values'
lc0 commented 5 years ago

Seems like it was my local error related to envs on Colab. Do you you think we can check these more explicitly?

jvdillon commented 5 years ago

On Sat, Mar 9, 2019 at 1:55 PM Sergii Khomenko notifications@github.com wrote:

Seems like it was my local error related to envs on Colab. Do you you think we can check these more explicitly?

It certainly would be nice if we could, although I dont know how. Do you have any suggestions?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/tensorflow/probability/issues/322#issuecomment-471225818, or mute the thread https://github.com/notifications/unsubscribe-auth/ABFZtmM2Tc2rrZPuZujHdwy0EAe1g2BYks5vVC2zgaJpZM4bm6Ze .

lc0 commented 5 years ago

I mean, it's mostly for transition time. Very simple idea: Tensorflow has tf.version.VERSION, so what if we just fail on import if version is not compatible.

lc0 commented 5 years ago

I think it's a bigger questions what versions we do not expect run be executed together if any. What do you think, what versions are not compatible like in my example from above?

ghost commented 5 years ago

It seems more complicated than one error. seems as if TFP does not work with TF2 and raise many errors. see #323

lc0 commented 5 years ago

@ErmiaAzarkhalili would you mind to try with tf-nightly-2.0-preview. Something like https://colab.research.google.com/drive/1astt2Bkj6T7o4MAOx2Q4HYOKD65ZE1Jl#scrollTo=NwiLC1s2QHRW

jvdillon commented 5 years ago

Thanks @lc0!

tl;dr: Try this: pip install --upgrade tf-nightly-gpu-2.0-preview tfp-nightly (Drop the -gpu if you don't have one or want a smaller whl download.)

jvdillon commented 5 years ago

Please reopen if the above procedure didnt work for you. In the coming days we'll also update the GH home page.

sehargul-123 commented 5 years ago

/home/sehar/DeepSpeech/tensorflow/python/framework/dtypes.py:516: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_qint8 = np.dtype([("qint8", np.int8, 1)]) /home/sehar/DeepSpeech/tensorflow/python/framework/dtypes.py:517: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_quint8 = np.dtype([("quint8", np.uint8, 1)]) /home/sehar/DeepSpeech/tensorflow/python/framework/dtypes.py:518: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_qint16 = np.dtype([("qint16", np.int16, 1)]) /home/sehar/DeepSpeech/tensorflow/python/framework/dtypes.py:519: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_quint16 = np.dtype([("quint16", np.uint16, 1)]) /home/sehar/DeepSpeech/tensorflow/python/framework/dtypes.py:520: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_qint32 = np.dtype([("qint32", np.int32, 1)]) /home/sehar/DeepSpeech/tensorflow/python/framework/dtypes.py:525: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. np_resource = np.dtype([("resource", np.ubyte, 1)]) /home/sehar/venv/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:541: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_qint8 = np.dtype([("qint8", np.int8, 1)]) /home/sehar/venv/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:542: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_quint8 = np.dtype([("quint8", np.uint8, 1)]) /home/sehar/venv/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:543: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_qint16 = np.dtype([("qint16", np.int16, 1)]) /home/sehar/venv/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:544: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_quint16 = np.dtype([("quint16", np.uint16, 1)]) /home/sehar/venv/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:545: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_qint32 = np.dtype([("qint32", np.int32, 1)]) /home/sehar/venv/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:550: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. np_resource = np.dtype([("resource", np.ubyte, 1)]) WARNING:tensorflow:From /home/sehar/DeepSpeech/tensorflow/python/data/ops/dataset_ops.py:494: py_func (from tensorflow.python.ops.script_ops) is deprecated and will be removed in a future version. Instructions for updating: tf.py_func is deprecated in TF V2. Instead, there are two options available in V2.

W1024 13:33:04.438267 140035658102592 deprecation.py:323] From /home/sehar/DeepSpeech/tensorflow/python/data/ops/dataset_ops.py:494: py_func (from tensorflow.python.ops.script_ops) is deprecated and will be removed in a future version. Instructions for updating: tf.py_func is deprecated in TF V2. Instead, there are two options available in V2.

WARNING:tensorflow:From /home/sehar/DeepSpeech/tensorflow/python/data/ops/iterator_ops.py:348: Iterator.output_types (from tensorflow.python.data.ops.iterator_ops) is deprecated and will be removed in a future version. Instructions for updating: Use tf.compat.v1.data.get_output_types(iterator). W1024 13:33:04.508710 140035658102592 deprecation.py:323] From /home/sehar/DeepSpeech/tensorflow/python/data/ops/iterator_ops.py:348: Iterator.output_types (from tensorflow.python.data.ops.iterator_ops) is deprecated and will be removed in a future version. Instructions for updating: Use tf.compat.v1.data.get_output_types(iterator). WARNING:tensorflow:From /home/sehar/DeepSpeech/tensorflow/python/data/ops/iterator_ops.py:349: Iterator.output_shapes (from tensorflow.python.data.ops.iterator_ops) is deprecated and will be removed in a future version. Instructions for updating: Use tf.compat.v1.data.get_output_shapes(iterator). W1024 13:33:04.508934 140035658102592 deprecation.py:323] From /home/sehar/DeepSpeech/tensorflow/python/data/ops/iterator_ops.py:349: Iterator.output_shapes (from tensorflow.python.data.ops.iterator_ops) is deprecated and will be removed in a future version. Instructions for updating: Use tf.compat.v1.data.get_output_shapes(iterator). WARNING:tensorflow:From /home/sehar/DeepSpeech/tensorflow/python/data/ops/iterator_ops.py:351: Iterator.output_classes (from tensorflow.python.data.ops.iterator_ops) is deprecated and will be removed in a future version. Instructions for updating: Use tf.compat.v1.data.get_output_classes(iterator). W1024 13:33:04.509080 140035658102592 deprecation.py:323] From /home/sehar/DeepSpeech/tensorflow/python/data/ops/iterator_ops.py:351: Iterator.output_classes (from tensorflow.python.data.ops.iterator_ops) is deprecated and will be removed in a future version. Instructions for updating: Use tf.compat.v1.data.get_output_classes(iterator). WARNING:tensorflow: The TensorFlow contrib module will not be included in TensorFlow 2.0. For more information, please see:

W1024 13:33:04.932764 140035658102592 lazy_loader.py:50] The TensorFlow contrib module will not be included in TensorFlow 2.0. For more information, please see:

WARNING:tensorflow:From /home/sehar/DeepSpeech/tensorflow/python/ops/init_ops.py:1251: calling VarianceScaling.init (from tensorflow.python.ops.init_ops) with dtype is deprecated and will be removed in a future version. Instructions for updating: Call initializer instance with the dtype argument instead of passing it to the constructor W1024 13:33:04.935033 140035658102592 deprecation.py:506] From /home/sehar/DeepSpeech/tensorflow/python/ops/init_ops.py:1251: calling VarianceScaling.init (from tensorflow.python.ops.init_ops) with dtype is deprecated and will be removed in a future version. Instructions for updating: Call initializer instance with the dtype argument instead of passing it to the constructor WARNING:tensorflow:From DeepSpeech.py:232: add_dispatch_support..wrapper (from tensorflow.python.ops.array_ops) is deprecated and will be removed in a future version. Instructions for updating: Use tf.where in 2.0, which has the same broadcast rule as np.where W1024 13:33:05.687577 140035658102592 deprecation.py:323] From DeepSpeech.py:232: add_dispatch_support..wrapper (from tensorflow.python.ops.array_ops) is deprecated and will be removed in a future version. Instructions for updating: Use tf.where in 2.0, which has the same broadcast rule as np.where I Initializing variables... I STARTING Optimization Traceback (most recent call last): File "DeepSpeech.py", line 906, in absl.app.run(main) File "/home/sehar/venv/lib/python3.6/site-packages/absl/app.py", line 299, in run _run_main(main, args) File "/home/sehar/venv/lib/python3.6/site-packages/absl/app.py", line 250, in _run_main sys.exit(main(argv)) File "DeepSpeech.py", line 890, in main train() File "DeepSpeech.py", line 608, in train trainloss, = run_set('train', epoch, train_init_op) File "DeepSpeech.py", line 566, in run_set pbar = create_progressbar(prefix=prefix, widgets=widgets, suffix=suffix).start() File "/home/sehar/DeepSpeech/util/logging.py", line 42, in create_progressbar return progressbar.ProgressBar(*args, **kwargs) TypeError: init() got an unexpected keyword argument 'prefix'

sehargul-123 commented 5 years ago

this is my error while my run file for training my own model

brianwa84 commented 5 years ago

Looks like an error in your code in logging.py initializing a progress bar.

On Thu, Oct 24, 2019, 4:49 AM sehargul-123 notifications@github.com wrote:

this is my error while my run file for training my own model

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/tensorflow/probability/issues/322?email_source=notifications&email_token=AFJFSIYDEH3GAR2HNWANLODQQFOSJA5CNFSM4G43UZPKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECEHXOI#issuecomment-545815481, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFJFSI2VC7F37G5P2IXOTDLQQFOSJANCNFSM4G43UZPA .

sehargul-123 commented 5 years ago

from future import print_function

import progressbar import sys

from util.flags import FLAGS

Logging functions

=================

def prefix_print(prefix, message): print(prefix + ('\n' + prefix).join(message.split('\n')))

def log_debug(message): if FLAGS.log_level == 0: prefix_print('D ', message)

def log_info(message): if FLAGS.log_level <= 1: prefix_print('I ', message)

def log_warn(message): if FLAGS.log_level <= 2: prefix_print('W ', message)

def log_error(message): if FLAGS.log_level <= 3: prefix_print('E ', message)

def create_progressbar(*args, **kwargs):

Progress bars in stdout by default

if 'fd' not in kwargs:
    kwargs['fd'] = sys.stdout

if FLAGS.show_progressbar:
    return progressbar.ProgressBar(*args, **kwargs)

return progressbar.NullBar(*args, **kwargs)

def log_progress(message): if not FLAGS.show_progressbar: log_info(message) what do I have to change in logging.py to resolve this error

sehargul-123 commented 5 years ago

i have progressbar=2.5 and progressbar2=3.47.0

brianwa84 commented 5 years ago

The error here is not in TF probability code, so we can't really help. The error is somewhere between DeepSpeech.py and util/logging.py.

sehargul-123 commented 5 years ago

kindly help me to indicate that error


From: Brian Patton notifications@github.com Sent: Monday, November 4, 2019 7:21 PM To: tensorflow/probability probability@noreply.github.com Cc: sehargul-123 sehar_capricon@hotmail.com; Comment comment@noreply.github.com Subject: Re: [tensorflow/probability] Python 3 + TF2 - TypeError: init() got an unexpected keyword argument 'values' (#322)

The error here is not in TF probability code, so we can't really help. The error is somewhere between DeepSpeech.py and util/logging.py.

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/tensorflow/probability/issues/322?email_source=notifications&email_token=ANPWXS5ULEFJ3N3D5VZHTUDQSAVVJA5CNFSM4G43UZPKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEC7M2KQ#issuecomment-549375274, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ANPWXS4BZ7QMP3ERHOZTJYTQSAVVJANCNFSM4G43UZPA.

sehargul-123 commented 5 years ago

can you please help me in indicating that error


From: Brian Patton notifications@github.com Sent: Monday, November 4, 2019 7:21 PM To: tensorflow/probability probability@noreply.github.com Cc: sehargul-123 sehar_capricon@hotmail.com; Comment comment@noreply.github.com Subject: Re: [tensorflow/probability] Python 3 + TF2 - TypeError: init() got an unexpected keyword argument 'values' (#322)

The error here is not in TF probability code, so we can't really help. The error is somewhere between DeepSpeech.py and util/logging.py.

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/tensorflow/probability/issues/322?email_source=notifications&email_token=ANPWXS5ULEFJ3N3D5VZHTUDQSAVVJA5CNFSM4G43UZPKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEC7M2KQ#issuecomment-549375274, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ANPWXS4BZ7QMP3ERHOZTJYTQSAVVJANCNFSM4G43UZPA.

lissyx commented 4 years ago

i have progressbar=2.5 and progressbar2=3.47.0

@sehargul-123 As @brianwa84 said, this is not tensorflow-level issue, this is you not following the documentations. Our requirements.txt specifies progressbar2, if you installed both then it's likely picking the wrong one and explains your issue ...

sehargul-123 commented 4 years ago

thanks problem resolve