[英]Stop showing progress bar in Jupyter Notebook output cell, and show only specific output
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()
我正在尝试在上面运行此单元格并仅打印“已验证”或“未验证”行,但在执行该单元格时 output 是这样的:
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
关于如何摆脱的任何建议:1/1 [===================] - 0s 244ms/step
并且只打印“已验证”或“未验证”的所需 output?
谢谢
验证 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
如果您可以隔离产生所有嘈杂 output 的确切行或行,则可以使用io.capture_output 将其嵌套在 with 语句中,如此处所述,基本上捕获所有不需要的 Z78E6221F6393D1356681DB398 。
您必须将您的打印语句或“已验证”或“未验证”放在您放入with
上下文中的任何内容之外。
无法说出它有多容易完成,因为您没有提供其他人可以轻松使用的最小可复制示例。 (您似乎设置了一些视频捕捉功能,我怀疑很多人都有。)
或者,您可以使用%%capture out
单元格魔法,请参见此处和此处的底部,在主单元格中,然后在下面的第二个单元格中,从收集的out.stdout
字符串中解析出验证/非验证行和显示那些。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.