C3W3 Assignment Question Duplicates Exercise 4 help needed

Help needed for C3W3 Assignment Question Duplicates Exercise 4 part:
I need perform prediction for the model for evaluation:
The default code already give:
test_gen = tf.data.Dataset.from_tensor_slices(((test_Q1, test_Q2),None)).batch(batch_size=batch_size)

I started my code to iterate test_gen as:

for step, (q, p) in enumerate(test_gen):
v1, v2 = model(q, training=False)

However, i got errors for prediction input parameters as:

Error message:
—> 30 v1, v2 = model(q, training=False)
31 # v1, v2 = model((q1, q2))
32 # print("v1: ", v1)
33 # print("v2: ", v2)
34 break

ValueError: too many values to unpack (expected 2)

I guess input parameter for model need some operations for tuples. q is a tuple directly from test_gen tensorflow dataset.

tuples size here should be 2.

Any help is welcome.

Hi @Zhiyi_Li2

As I mentioned in your previous question - you don’t need the for loop here.

Take a look at what your Exercise 01 Siamese(..) function accomplishes - it returns v1 and v2 concatenated. So what you need is pred = model.predict(..) - specify correct arguments, first one should be your input, the second one is verbose for illustration.

The next three lines essentially separates the v1 and v2 out from pred (which have them concatenated). Similar question how to get these.

Let me know if that is clear.

My errors is like this:
v1, v2 = model.predict(test_gen)

ValueError: too many values to unpack (expected 2)

Solved: I wrote code as:

pred = model.predict(next(iter(test_gen))[0], verbose=0)

[0] is corresponding to (q1, q2) tuple.

It is working, but still need loop the dataset with next(iter(test_gen), right?