You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to train a DeepIV model as per the example in the documentation. I have tried doing so using native keras, as well as via tensorflow. In both cases, I encounter an AttributeError, although with slightly different stacktraces.
Given a choice, I would prefer to use tensorflow rather than native keras.
Versions
Keras: 2.3.1 (using tensorflow backend)
TensorFlow: 2.3.0
Econml: 0.10.0
Using keras
Code to replicate the issue:
importkerasfromeconml.iv.nnetimportDeepIVtreatment_model=keras.Sequential([keras.layers.Dense(128, activation='relu', input_shape=(2,)),
keras.layers.Dropout(0.17),
keras.layers.Dense(64, activation='relu'),
keras.layers.Dropout(0.17),
keras.layers.Dense(32, activation='relu'),
keras.layers.Dropout(0.17)])
response_model=keras.Sequential([keras.layers.Dense(128, activation='relu', input_shape=(2,)),
keras.layers.Dropout(0.17),
keras.layers.Dense(64, activation='relu'),
keras.layers.Dropout(0.17),
keras.layers.Dense(32, activation='relu'),
keras.layers.Dropout(0.17),
keras.layers.Dense(1)])
est=DeepIV(n_components=10, # Number of gaussians in the mixture density networks)m=lambdaz, x: treatment_model(keras.layers.concatenate([z, x])), # Treatment modelh=lambdat, x: response_model(keras.layers.concatenate([t, x])), # Response modeln_samples=1# Number of samples used to estimate the response
)
est.fit(Y, T, X=X, Z=Z) # Z -> instrumental variablestreatment_effects=est.effect(X_test)
Stack trace:
AttributeErrorTraceback (mostrecentcalllast)
<ipython-input-5-263e9f75519e>in<module>7keras.layers.Dropout(0.17),
8keras.layers.Dense(32, activation='relu'),
---->9keras.layers.Dropout(0.17)])
10response_model=keras.Sequential([keras.layers.Dense(128, activation='relu', input_shape=(2,)),
11keras.layers.Dropout(0.17),
~/.pyenv/versions/miniconda3-4.3.30/envs/my-project/lib/python3.7/site-packages/keras/engine/sequential.pyin__init__(self, layers, name)
92iflayers:
93forlayerinlayers:
--->94self.add(layer)
9596 @property~/.pyenv/versions/miniconda3-4.3.30/envs/my-project/lib/python3.7/site-packages/keras/engine/sequential.pyinadd(self, layer)
164# and create the node connecting the current layer165# to the input layer we just created.-->166layer(x)
167set_inputs=True168else:
~/.pyenv/versions/miniconda3-4.3.30/envs/my-project/lib/python3.7/site-packages/keras/backend/tensorflow_backend.pyinsymbolic_fn_wrapper(*args, **kwargs)
73if_SYMBOLIC_SCOPE.value:
74withget_graph().as_default():
--->75returnfunc(*args, **kwargs)
76else:
77returnfunc(*args, **kwargs)
~/.pyenv/versions/miniconda3-4.3.30/envs/my-project/lib/python3.7/site-packages/keras/engine/base_layer.pyin__call__(self, inputs, **kwargs)
444# Raise exceptions in case the input is not compatible445# with the input_spec specified in the layer constructor.-->446self.assert_input_compatibility(inputs)
447448# Collect input shapes to build layer.~/.pyenv/versions/miniconda3-4.3.30/envs/my-project/lib/python3.7/site-packages/keras/engine/base_layer.pyinassert_input_compatibility(self, inputs)
308forxininputs:
309try:
-->310K.is_keras_tensor(x)
311exceptValueError:
312raiseValueError('Layer ' +self.name+ ' wascalledwith '
~/.pyenv/versions/miniconda3-4.3.30/envs/my-project/lib/python3.7/site-packages/keras/backend/tensorflow_backend.pyinis_keras_tensor(x)
693```
694 """
--> 695 if not is_tensor(x):
696 raise ValueError('Unexpectedly found an instance of type `' +
697 str(type(x)) + '`. '
~/.pyenv/versions/miniconda3-4.3.30/envs/my-project/lib/python3.7/site-packages/keras/backend/tensorflow_backend.py in is_tensor(x)
701
702 def is_tensor(x):
--> 703 return isinstance(x, tf_ops._TensorLike) or tf_ops.is_dense_tensor_like(x)
704
705
AttributeError: module 'tensorflow.python.framework.ops' has no attribute '_TensorLike'
AttributeErrorTraceback (mostrecentcalllast)
<ipython-input-9-a7333673df03>in<module>21n_samples=222 )
--->23deepIv.fit(y, p, X=x, Z=z)
~/.pyenv/versions/miniconda3-4.3.30/envs/my-project/lib/python3.7/site-packages/econml/utilities.pyinm(*args, **kwargs)
1260ifwrong_args:
1261warn(message, category, stacklevel=2)
->1262returnto_wrap(*args, **kwargs)
1263returnm1264returndecorator~/.pyenv/versions/miniconda3-4.3.30/envs/my-project/lib/python3.7/site-packages/econml/_cate_estimator.pyincall(self, Y, T, inference, *args, **kwargs)
128inference.prefit(self, Y, T, *args, **kwargs)
129# call the wrapped fit method-->130m(self, Y, T, *args, **kwargs)
131self._postfit(Y, T, *args, **kwargs)
132ifinferenceisnotNone:
~/.pyenv/versions/miniconda3-4.3.30/envs/my-project/lib/python3.7/site-packages/econml/iv/nnet/_deepiv.pyinfit(self, Y, T, X, Z, inference)
337n_components=self._n_components338-->339treatment_network=self._m(z_in, x_in)
340341# the dimensionality of the output of the network<ipython-input-9-a7333673df03>in<lambda>(z, x)
17deepIv=DeepIV(
18n_components=10,
--->19m=lambdaz, x: treatment_model(tf.keras.layers.concatenate([z, x])),
20h=lambdat, x: hmodel(tf.keras.layers.concatenate([t, x])),
21n_samples=2~/.pyenv/versions/miniconda3-4.3.30/envs/my-project/lib/python3.7/site-packages/tensorflow/python/keras/layers/merge.pyinconcatenate(inputs, axis, **kwargs)
929Atensor, theconcatenationoftheinputsalongsideaxis`axis`.
930 """
--> 931 return Concatenate(axis=axis, **kwargs)(inputs)
932
933
~/.pyenv/versions/miniconda3-4.3.30/envs/my-project/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py in __call__(self, *args, **kwargs)
924 if _in_functional_construction_mode(self, inputs, args, kwargs, input_list):
925 return self._functional_construction_call(inputs, args, kwargs,
--> 926 input_list)
927
928 # Maintains info about the `Layer.call` stack.
~/.pyenv/versions/miniconda3-4.3.30/envs/my-project/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py in _functional_construction_call(self, inputs, args, kwargs, input_list)
1145 # Node connectivity does not special-case the first argument.
1146 outputs = self._set_connectivity_metadata((inputs,) + args, kwargs,
-> 1147 outputs)
1148 self._handle_activity_regularization(inputs, outputs)
1149 self._set_mask_metadata(inputs, outputs, input_masks, True)
~/.pyenv/versions/miniconda3-4.3.30/envs/my-project/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py in _set_connectivity_metadata(self, args, kwargs, outputs)
2573 # `_outbound_nodes` of the layers that produced the inputs to this
2574 # layer call.
-> 2575 node_module.Node(self, call_args=args, call_kwargs=kwargs, outputs=outputs)
2576 return outputs
2577
~/.pyenv/versions/miniconda3-4.3.30/envs/my-project/lib/python3.7/site-packages/tensorflow/python/keras/engine/node.py in __init__(self, layer, call_args, call_kwargs, outputs)
102 self.layer._inbound_nodes.append(self)
103 for kt in self.keras_inputs:
--> 104 inbound_layer = kt._keras_history.layer
105 if inbound_layer is not None: # `None` for `Input` tensors.
106 inbound_layer._outbound_nodes.append(self)
AttributeError: 'tuple' object has no attribute 'layer'
Addendum
I'm wondering if this might be due to some version incompatibility issues but was unable to find any information regarding this on the documentation. Any help would be greatly appreciated!
The text was updated successfully, but these errors were encountered:
Thanks for the report and sorry for the inconvenience. Unfortunately, Tensorflow 2.3 and above are not currently supported (see also #352); this is being fixed in #389 but we don't have a firm date by which we expect to complete that work.
I'm trying to train a DeepIV model as per the example in the documentation. I have tried doing so using native keras, as well as via tensorflow. In both cases, I encounter an
AttributeError
, although with slightly different stacktraces.Given a choice, I would prefer to use tensorflow rather than native keras.
Versions
Using keras
Code to replicate the issue:
Stack trace:
Using TensorFlow
Code to replicate the issue:
Stack trace:
Addendum
I'm wondering if this might be due to some version incompatibility issues but was unable to find any information regarding this on the documentation. Any help would be greatly appreciated!
The text was updated successfully, but these errors were encountered: