Hi, I have trouble on C3W43Assignment Exercise 4 Samese model for question duplicates: Evaluation part exercise 4:
There the default test data created by default:
test_gen = tf.data.Dataset.from_tensor_slices(((test_Q1, test_Q2),None)).batch(batch_size=batch_size)
However, when I perform evaluation with already test data by utilize test_gen, I am stuck
Here is my part of pseuduo code:
for i in range(0, len(test_Q1)):
element = next(iter(test_gen))
How can I use element with a batched data to feed in the model ?
I think:
v1, v2 = model(q1, q2)
However how to get q1, q2 correct as input to the model ?
Zhiyi
When creating a post, please add:
Week # must be added in the tags option of the post.
Link to the classroom item you are referring to:
Description (include relevant info but please do not post solution code or your entire notebook)
I noticed output of next(iter(test_gen)) is tuple include test_Q1, and test_Q2 information already, but still not get correct in model input parameters.
You do not need the for loop. The test_gen is an iterable object and you can pass it to model.predict(..).
And as you later realized, the test_gen is already a tuple, so you don’t have to worry about wrapping (test_Q1, test_Q2) as it is already in the test_gen.
Errors for model prediction part for model((x1,x2))
x, y = iterator.get_next()
x1, x2 = x
# print ("x1: ", x1)
# print ("x2: ", x2)
v1, v2 = model((x1, x2))
Error message is: too many values to unpack (expected 2)
When I run model to predict for test data, input should be test_Q1, test_Q2. How can I get input correct ?
Problem for C3W3_Assignment Duplicate questions exercise 4 errors:
I need create v1, v2 based on the Siamese model: Here is my snippet of code:
for elem in test_gen:
v1, v2 = model.predict(elem[0])
The error complains as: too many values to unpack (expected 2)
I think model.predict(…) function expect a tuple (Question 1, Question 2). However, elem[0] is exactly from test_gen, can help to fix this too many values to unpack errors ?
Yes, that is what I meant, by that you don’t need to pack Q1 and Q2 again. In the train_dataset it was ((q1, q2), 1), but here instead of 1, we use None.
Did you solve your issue? What was the problem if you did?
I use the code:
pred = model.predict(next(iter(test_gen)), verbose=0)
The system complains cannot handle None type as errors:
Inputs to a layer should be tensors. Got ‘None’ (of type <class ‘NoneType’>) as input for layer ‘SiameseModel’.
I think next(iter(test_gen)) has a size 2, one for (q,1,q2), another for None, It cause the system cannot handle None type, What is really input for pred = model.predict() is? second parameter verbose = 0 already done, what is first parameter ?