0

Hi I'm trying to make a network using transfer learning while fine tunning a VGGFace implementation:

img_height, img_width = 224,224
module=VGGFace(model = 'resnet50',include_top = False,weights = 'vggface',input_shape = (img_height, img_width, 3))

model = tf.keras.Sequential([
    tf.keras.layers.InputLayer(input_shape=(img_height, img_width, 3)),             
    tf.keras.layers.Lambda(lambda x: utils.preprocess_input(np.expand_dims(x, axis=0), version=2)),
    module,
    tf.keras.layers.Flatten(),
    tf.keras.layers.Dense(256, activation="relu"),
    tf.keras.layers.Dense(num, "sigmoid"), 
])

But the following error comes up:

Cannot convert a symbolic Tensor (Placeholder:0) to a numpy array. This error may indicate that you're trying to pass a Tensor to a NumPy call, which is not supported

I guess it's because the utils.preprocess_input function which is meant for numpy arrays and not for tensors, but I need it to be in the network architecture since I'm dealing with a lot images and I can't store them all at once. Any suggestions how to make it work?

lmglm
  • 3
  • 2
  • The error speaks itself: you're trying to pass a Tensor to a NumPy call. Try this: `utils.preprocess_input(np.expand_dims(x.numpy(), axis=0), version=2)` – Mert Köklü Mar 01 '21 at 01:58
  • @MertKöklü Thanks, i agree with you! I tried different ways to turn a tensor to an array but nothing seems to work, this one says `'Tensor' object has no attribute 'numpy'` – lmglm Mar 01 '21 at 03:21

1 Answers1

0

you are trying to expand the dimension of tensor with numpy expand_dims. try this:

utils.preprocess_input(tf.expand_dims(x, axis=0), version=2)