0

New to the Keras model implementation and despite looking for answers: https://stackoverflow.com/questions/60991253/invalidargumenterror-input-must-be-a-vector-got-shape https://stackoverflow.com/questions/41736677/how-could-keras-model-predict-only-one-sample

But still couldnt make it work :(

I successfully trained my Keras model (words embeddings using "https://tfhub.dev/google/universal-sentence-encoder/4")

But when I try to predict with:

test_text = ["We are looking for Data Scientists"]
test_text = np.array(test_text , dtype=object)[:, np.newaxis]

predicts = model.predict(test_text , batch_size=32)
predicts

But I get the following error:

InvalidArgumentError                      Traceback (most recent call last)
<ipython-input-150-078cff510ad4> in <module>
----> 1 predicts = model.predict(test_text, batch_size=32)
      2 
      3 predicts

1 frames
/usr/local/lib/python3.7/dist-packages/tensorflow/python/eager/execute.py in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
     53     ctx.ensure_initialized()
     54     tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
---> 55                                         inputs, attrs, num_outputs)
     56   except core._NotOkStatusException as e:
     57     if name is not None:

InvalidArgumentError: Graph execution error:

input must be a vector, got shape: []
     [[{{node text_preprocessor/tokenize/StringSplit/StringSplit}}]] [Op:__inference_predict_function_838262]

Below the model summary and the batch input shape required - but really dont get it to work :(

Any HELP more than welcome!!!

Thanks

>> model.summary()

Model: "model"

_________________________________________________________________

Layer (type)                Output Shape              Param #
=

input_18 (InputLayer)       \[(None, 1)\]               0

lambda_14 (Lambda)          (None, 512)               0

dense_1 (Dense)             (None, 256)               131328

dense_2 (Dense)             (None, 788)               202516

=================================================================
Total params: 333,844
Trainable params: 333,844
Non-trainable params: 0
config = model.get_config() # Returns pretty much every information about your model
print(config\["layers"\]\[0\]\["config"\]\["batch_input_shape"\]) # returns a tuple of width, height and channels

(None, 1)

Looking at some answers like Keras model input shape wrong

I also tried to reshape like that

predicts = model.predict(test_text.reshape((1, -1)))

predicts

But I get exactly the same error than previously

flohaha
  • 1
  • 1

0 Answers0