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+' was called with '~/.pyenv/versions/miniconda3-4.3.30/envs/my-project/lib/python3.7/site-packages/keras/backend/tensorflow_backend.pyinis_keras_tensor(x)
693```
694 """
-->695ifnotis_tensor(x):
696raiseValueError('Unexpectedly found an instance of type `'+697str(type(x)) +'`. '~/.pyenv/versions/miniconda3-4.3.30/envs/my-project/lib/python3.7/site-packages/keras/backend/tensorflow_backend.pyinis_tensor(x)
701702defis_tensor(x):
-->703returnisinstance(x, tf_ops._TensorLike) ortf_ops.is_dense_tensor_like(x)
704705AttributeError: module'tensorflow.python.framework.ops'hasnoattribute'_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 """
-->931returnConcatenate(axis=axis, **kwargs)(inputs)
932933~/.pyenv/versions/miniconda3-4.3.30/envs/my-project/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.pyin__call__(self, *args, **kwargs)
924if_in_functional_construction_mode(self, inputs, args, kwargs, input_list):
925returnself._functional_construction_call(inputs, args, kwargs,
-->926input_list)
927928# 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.pyin_functional_construction_call(self, inputs, args, kwargs, input_list)
1145# Node connectivity does not special-case the first argument.1146outputs=self._set_connectivity_metadata((inputs,) +args, kwargs,
->1147outputs)
1148self._handle_activity_regularization(inputs, outputs)
1149self._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.pyin_set_connectivity_metadata(self, args, kwargs, outputs)
2573# `_outbound_nodes` of the layers that produced the inputs to this2574# layer call.->2575node_module.Node(self, call_args=args, call_kwargs=kwargs, outputs=outputs)
2576returnoutputs2577~/.pyenv/versions/miniconda3-4.3.30/envs/my-project/lib/python3.7/site-packages/tensorflow/python/keras/engine/node.pyin__init__(self, layer, call_args, call_kwargs, outputs)
102self.layer._inbound_nodes.append(self)
103forktinself.keras_inputs:
-->104inbound_layer=kt._keras_history.layer105ifinbound_layerisnotNone: # `None` for `Input` tensors.106inbound_layer._outbound_nodes.append(self)
AttributeError: 'tuple'objecthasnoattribute'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: