2

Input Cell

cap = cv2.VideoCapture(0)
while cap.isOpened():
    ret, frame = cap.read()
    frame = frame[120:120+250,200:200+250, :]

    cv2.imshow('Verification', frame, )

    # Verification trigger
    if cv2.waitKey(10) & 0xFF == ord('v'):
        # Save input image to application_data/input_image folder 
        cv2.imwrite(os.path.join('app_data', 'input_image', 'input_image.jpg'), frame)
        # Run verification
        results, verified = verify(model, 0.9, 0.7)
        if verified == True:
            print('Verified')
        else:
            print('Not Verified')
 
        
    if cv2.waitKey(10) & 0xFF == ord('q'):
       break
    
cap.release()
cv2.destroyAllWindows()

I'm trying to run this cell above and print only the "verified" or "not verified" lines, but when executing the cell the output is like this:

Output Cell

1/1 [==============================] - 0s 202ms/step
1/1 [==============================] - 0s 208ms/step
1/1 [==============================] - 0s 208ms/step
1/1 [==============================] - 0s 203ms/step
1/1 [==============================] - 0s 272ms/step
1/1 [==============================] - 0s 221ms/step
1/1 [==============================] - 0s 217ms/step
1/1 [==============================] - 0s 208ms/step
Not Verified

Any suggestions on how to get rid of the: 1/1 [===================] - 0s 244ms/step

and only print the desired output of "verified" or "not verified"?

Thanks!

the verify function:

def verify(model, detection_threshold, verification_threshold):
# Build results array
results = []
for image in os.listdir(os.path.join('application_data', 'verification_images')):
    input_img = preprocess(os.path.join('application_data', 'input_image', 'input_image.jpg'))
    validation_img = preprocess(os.path.join('application_data', 'verification_images', image))
    
    # Make Predictions 
    result = model.predict(list(np.expand_dims([input_img, validation_img], axis=1)))
    results.append(result)

# Detection Threshold: Metric above which a prediciton is considered positive 
detection = np.sum(np.array(results) > detection_threshold)

# Verification Threshold: Proportion of positive predictions / total positive samples 
verification = detection / len(os.listdir(os.path.join('application_data', 'verification_images'))) 
verified = verification > verification_threshold

return results, verified
tomh
  • 31
  • 2

1 Answers1

1

If you can isolate the exact line or lines that make all the noisy output, you can nest that in a with statement using io.capture_output as described here to essentially capture all the unwanted output and not do anything with out.

You'd have to though have your print statements or "verified" or "not verified" outside of anything you put in the with context.

Cannot tell how easily it would be done because you don't provide a minimal reproducible example that others could easily use. (Your seem to have something set up with video capture that I doubt a lot of people have.)

Alternatively, you can use the %%capture out cell magic, see here and bottom of here, in the main cell and then in a second cell below that parse out just the verification / non-verification lines from the collected out.stdout string and show those.

Wayne
  • 6,607
  • 8
  • 36
  • 93