-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NameError: name 'keras' is not defined #317
Comments
Thanks Ill take a look Was this from a notebook here in the repo or something else ? |
It was on Jupyter notebook. I fixed it by modifying the file anaconda3/envs/tf216/lib/python3.10/site-packages/weightwatcher/weightwatcher.py However still getting some warning I’m using TF 2.17.0 |
is this a notebook you downloaded from the github repo or one you created ?you don’t need to add an import to weightwatcher it will automatically detect tensorflow in your environmentI wil check locally and get back to you in a few hours Sent from my iPhoneOn Sep 14, 2024, at 10:36 AM, Shahariar Rabby ***@***.***> wrote:
It was on Jupyter notebook. I fixed it by modifying the file anaconda3/envs/tf216/lib/python3.10/site-packages/weightwatcher/weightwatcher.py
Added from tensorflow import keras.
However still getting some warning
Critical: tensorflow load failed
Critical: Keras load failed
I’m using TF 2.17.0
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: ***@***.***>
|
im not able to reproduce it is this one of the notebooks provided in the github repo and/or can you join the discord to discuss ? |
I tried to do this with my model and got the error then I tried the code from example notebook and got same error.
|
2024-09-14 04:23:33,200 - CRITICAL - Can not load tensorflow or keras, stopping
2024-09-14 04:23:33,201 - CRITICAL - Can not load tensorflow or keras, stopping
NameError Traceback (most recent call last)
Cell In[17], line 4
2 import keras
3 watcher = ww.WeightWatcher(model=model)
----> 4 details = watcher.describe()
File ~/anaconda3/envs/tf216/lib/python3.10/site-packages/weightwatcher/weightwatcher.py:3769, in WeightWatcher.describe(self, model, layers, min_evals, max_evals, min_size, max_size, max_N, glorot_fix, savefig, ww2x, pool, conv2d_fft, fft, conv2d_norm, intra, channels, stacked, start_ids, base_model, peft)
3766 details = pd.DataFrame(columns=[])
3768 num_all_evals = 0
-> 3769 for ww_layer in layer_iterator:
3770 if not ww_layer.skipped and ww_layer.has_weights:
3771 #logger.debug("LAYER TYPE: {} {} layer type {}".format(ww_layer.layer_id, ww_layer.the_type, type(ww_layer.framework_layer)))
3772 #logger.debug("layer_id {} weights shape : {} max size {}".format(ww_layer.layer_id,ww_layer.weights.shape, params['max_evals']))
3773 if not pool:
File ~/anaconda3/envs/tf216/lib/python3.10/site-packages/weightwatcher/weightwatcher.py:1423, in ModelIterator.next(self)
1422 def next(self):
-> 1423 return self.next()
File ~/anaconda3/envs/tf216/lib/python3.10/site-packages/weightwatcher/weightwatcher.py:1426, in ModelIterator.next(self)
1425 def next(self):
-> 1426 curr_layer = next(self.layer_iter)
1427 if curr_layer:
1428 return curr_layer
File ~/anaconda3/envs/tf216/lib/python3.10/site-packages/weightwatcher/weightwatcher.py:1620, in WWLayerIterator.ww_layer_iter_(self)
1617 def ww_layer_iter_(self):
1618 """Create a generator for iterating over ww_layers"""
-> 1620 for curr_layer in self.model_iter:
1622 is_skipped = True
1623 is_supported = False
File ~/anaconda3/envs/tf216/lib/python3.10/site-packages/weightwatcher/weightwatcher.py:273, in KerasLayer.get_layer_iterator..layer_iter_()
271 yield keras_layer
272 for layer in model.layers:
--> 273 yield from traverse_(layer)
File ~/anaconda3/envs/tf216/lib/python3.10/site-packages/weightwatcher/weightwatcher.py:264, in KerasLayer.get_layer_iterator..layer_iter_..traverse_(layer)
262 nonlocal layer_id
263 if not hasattr(layer, 'submodules') or len(layer.submodules)==0:
--> 264 keras_layer = KerasLayer(layer, layer_id)
265 layer_id += 1
266 yield keras_layer
File ~/anaconda3/envs/tf216/lib/python3.10/site-packages/weightwatcher/weightwatcher.py:149, in KerasLayer.init(self, layer, layer_id, name, longname)
147 def init(self, layer, layer_id, name=None, longname = None):
--> 149 the_type = self.layer_type(layer)
150 channels = CHANNELS.FIRST
151 FrameworkLayer.init(self, layer, layer_id, name, longname=longname, the_type=the_type,
152 framework=FRAMEWORK.KERAS, channels=channels)
File ~/anaconda3/envs/tf216/lib/python3.10/site-packages/weightwatcher/weightwatcher.py:165, in KerasLayer.layer_type(self, layer)
162 typestr = (str(type(layer))).lower()
164 # Keras TF 2.x types
--> 165 if isinstance(layer, keras.layers.Dense) or 'dense' in typestr:
166 the_type = LAYER_TYPE.DENSE
168 elif isinstance(layer, keras.layers.Conv1D) or 'conv1d' in typestr:
NameError: name 'keras' is not defined
The text was updated successfully, but these errors were encountered: