Reputation: 1395
I have a model from https://github.com/bonlime/keras-deeplab-v3-plus that I try to customize a bit.
I want to run it with Tensorflow Eager mode
from model import Deeplabv3
import tensorflow as tf
tf.enable_eager_execution()
model = Deeplabv3(weights='pascal_voc', input_shape=(200,200,3), backbone='mobilenetv2', classes=64)
batch = tf.zeros((1,200,200,3))
f = model(batch)
However this gives the error:
model.py", line 236, in _inverted_res_block in_channels = inputs._keras_shape[-1] AttributeError: 'DeferredTensor' object has no attribute '_keras_shape'
It is about this part of the code
def _inverted_res_block(inputs, expansion, stride, alpha, filters, block_id, skip_connection, rate=1):
in_channels = inputs._keras_shape[-1]
#in_channels = inputs.get_shape()[-1].value
#in_channels = tf.shape(inputs)[-1]
import pdb;pdb.set_trace()
pointwise_conv_filters = int(filters * alpha)
pointwise_filters = _make_divisible(pointwise_conv_filters, 8)
x = inputs
prefix = 'expanded_conv_{}_'.format(block_id)
if block_id:
# Expand
x = Conv2D(expansion * in_channels, kernel_size=1, padding='same',
use_bias=False, activation=None,
name=prefix + 'expand')(x)
How to solve this?
Upvotes: 2
Views: 1533
Reputation: 51
I have made this change:
Instead this line: in_channels = inputs.shape[-1].value or this other line: inputs._keras_shape[-1]
I have used this other: in_channels = inputs.shape.as_list()[-1]
and it works for me.
Upvotes: 0
Reputation: 6751
As P-gn pointed out:
tf.keras
(included with TensorFlow) supports eager execution, the keras
module does not.tf.keras
implements the keras
API spec, so it should be a drop-in replacement for any program using keras
(e.g., change references to keras.Model
to tf.keras.Model
). Plus it additionally supports eager execution in TensorFlow.Upvotes: 1