Skip to content
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

TF 2.4 raises a val err: Keras symbolic inputs/outputs do not impleme… #58

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions conda_gpu_py36.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: surgeon-py36-tf23-gpu

dependencies:
- python<3.7
- pip
- matplotlib
- opencv
- cudnn=7
- cudatoolkit
- pip:
- tensorflow-gpu==2.3
- numpy<=1.19.5
- opencv-python>=4.0
- keras
- lxml
- tqdm
21 changes: 13 additions & 8 deletions src/kerassurgeon/surgeon.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,15 +441,20 @@ def _apply_delete_mask(self, node, inbound_masks):
'MaxPooling3D',
'AveragePooling1D', 'AveragePooling2D',
'AveragePooling3D'):
index = [slice(None, x, None) for x in output_shape[1:]]
if data_format == 'channels_first':
index[0] = slice(None)
elif data_format == 'channels_last':
index[-1] = slice(None)

if output_shape is None:
outbound_mask = None
new_layer = layer
else:
raise ValueError('Invalid data format')
outbound_mask = inbound_masks[tuple(index)]
new_layer = layer
index = [slice(None, x, None) for x in output_shape[1:]]
if data_format == 'channels_first':
index[0] = slice(None)
elif data_format == 'channels_last':
index[-1] = slice(None)
else:
raise ValueError('Invalid data format')
outbound_mask = inbound_masks[tuple(index)]
new_layer = layer

elif layer_class in ('UpSampling1D',
'UpSampling2D',
Expand Down
23 changes: 17 additions & 6 deletions src/kerassurgeon/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import numpy as np
from tensorflow.keras.layers import Layer
from tensorflow.keras.activations import linear
from tensorflow.python.keras.engine import keras_tensor
import tensorflow as tf
from ._utils import node as node_utils

Expand Down Expand Up @@ -137,20 +138,30 @@ def sort_x_by_y(x, y):

def single_element(x):
"""If x contains a single element, return it; otherwise return x"""
if isinstance(x, tf.Tensor):

if isinstance(x, (tf.Tensor, keras_tensor.KerasTensor)):
return x

if len(x) == 1:
x = x[0]
if isinstance(x, list):
if len(x) == 1:
return x[0]

if isinstance(x, tuple):
return x[0]

return x


def get_one_tensor(x):
if isinstance(x, tf.Tensor):

if isinstance(x, (tf.Tensor, keras_tensor.KerasTensor)):
return x

assert len(x) == 1
return x[0]
if isinstance(x, list):
if len(x) == 1:
return x[0]

return x


def bool_to_index(x):
Expand Down