简体   繁体   English

在 colab 中打印和 cv2_imshow

[英]print and cv2_imshow in colab

def ensemble_predict(scheme_model,quality_model,rotate_model,img,y=None):


  quality_labels  = ["blur","sharp","torch"]
  rotate_labels = [0,90,-90,180]
  bgr_labels = ["bgr","rgb"]
  
  scheme_pred = scheme_model.predict(img)[0]
  quality_pred = quality_model.predict(img)[0]
  rotate_pred = rotate_model.predict(img)[0]
  cv2_imshow(cv2.resize(img[0]*255,(256,256)))
  
  p = scheme_pred
  scheme_pred = 0 if scheme_pred < 0.5 else 1 
  print("Predict BGR or RGB:", bgr_labels[scheme_pred], ", p:",p[0])
  print("Predict quality:", quality_labels[np.argmax(quality_pred)], ", p:", quality_pred[np.argmax(quality_pred)])
  print("Predict rotation:" ,rotate_labels[np.argmax(rotate_pred)], ", p:", rotate_pred[np.argmax(rotate_pred)])
  
  print()
  if y is not None:
    q_l = quality_labels[y[0]]
    r_l = rotate_labels[y[1]]
    b_l = bgr_labels[y[2]]
    print("True BGR or RGB:", b_l)
    print("True quality:", q_l)
    print("True rotation:" ,r_l)
  print()
  print()

output output

I work in google colab, how can I make a print to the right of the image that I output via cv2_imshow I have attached the sample code, I am glad to see the solution, but I am also ready to apply an alternative我在 google colab 工作,如何通过 cv2_imshow 在图像右侧打印 output 我附上了示例代码,很高兴看到解决方案,但我也准备应用替代方案

Try this:尝试这个:

def ensemble_predict(scheme_model,quality_model,rotate_model,img,y=None):


  quality_labels  = ["blur","sharp","torch"]
  rotate_labels = [0,90,-90,180]
  bgr_labels = ["bgr","rgb"]
  
  scheme_pred = scheme_model.predict(img)[0]
  quality_pred = quality_model.predict(img)[0]
  rotate_pred = rotate_model.predict(img)[0]
  cv2_imshow(cv2.resize(img[0]*255,(256,256)))
  print("",end='')
  p = scheme_pred
  scheme_pred = 0 if scheme_pred < 0.5 else 1 
  print("\t Predict BGR or RGB:", bgr_labels[scheme_pred], ", p:",p[0],end='')
  print("\t Predict quality:", quality_labels[np.argmax(quality_pred)], ", p:", quality_pred[np.argmax(quality_pred)],end='')
  print("\t Predict rotation:" ,rotate_labels[np.argmax(rotate_pred)], ", p:", rotate_pred[np.argmax(rotate_pred)],end='')
  
  print()
  if y is not None:
    q_l = quality_labels[y[0]]
    r_l = rotate_labels[y[1]]
    b_l = bgr_labels[y[2]]
    print("True BGR or RGB:", b_l)
    print("True quality:", q_l)
    print("True rotation:" ,r_l)
  print()
  print()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 cv2_imshow() 不在 Google Colab 中呈现视频文件 - cv2_imshow() doesn't render video file in Google Colab TypeError: cv2_imshow() 接受 1 个位置参数,但给出了 2 个:google colab cv 相关问题 - TypeError: cv2_imshow() takes 1 positional argument but 2 were given : google colab cv related problems google colab,cv2_imshow 抛出错误:'NoneType' object 没有属性'clip' - google colab, cv2_imshow throws error: 'NoneType' object has no attribute 'clip' cv2_imshow() 接受 1 个位置参数,但给出了 2 个 - cv2_imshow() takes 1 positional argument but 2 were given 'NoneType' object has no attribute 'clip' error in ```cv2_imshow()``` - 'NoneType' object has no attribute 'clip' error in ```cv2_imshow()``` 在谷歌 Colab 中使用 cv2.imshow() - Using cv2.imshow() in google Colab cv2_imshow collab 没有显示任何使用 cnn+l;stm 模型预测视频的内容 - cv2_imshow collab doesnt show anything for predicting video using cnn+l;stm model while cv2.imshow() 打印一段时间 - Print while cv2.imshow() for a period of time DisabledFunctionError: cv2.imshow() 在 Colab 中被禁用,因为它会导致 Jupyter 会话崩溃 - DisabledFunctionError: cv2.imshow() is disabled in Colab, because it causes Jupyter sessionsto crash cv2 :: imshow的参数 - Arguments to cv2::imshow
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM