Skip to content

Commit

Permalink
Update model_utils.py (#134)
Browse files Browse the repository at this point in the history
I ran into an issue where save_layer in model_utils.py is giving me an error that: AttributeError: 'Dense' object has no attribute 'output_shape'

I found that layer.output.shape works, but isn't always a tuple, which runs afoul of the JSON encoder. So I added check for that too.

I modified the code and it seems to work on Macos, Linux, Windows. I've included my debugging print statements so you can see what I was looking at.
  • Loading branch information
dsagman committed Mar 30, 2024
1 parent 0b0e5d0 commit a8ae9c5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion python/model_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,17 @@ def get_layer_activation(layer):


def save_layer(layer):
try:
outshape = layer.output_shape # this is the original code, but sometimes doesn't work
except:
outshape = layer.output.shape # if not, use this and make sure it's a tuple so it can be JSON encoded
if type(outshape) != tuple:
outshape = tuple(outshape.as_list())

layer_dict = {
"type" : get_layer_type(layer),
"activation" : get_layer_activation(layer),
"shape" : layer.output_shape,
"shape" : outshape, # modified to use the outshape above
}

if layer_dict["type"] == "conv1d":
Expand Down

0 comments on commit a8ae9c5

Please sign in to comment.