【问题标题】:Processing Only One Image Uses All of Ram仅处理一张图像会使用所有 Ram
【发布时间】:2021-12-07 14:55:19
【问题描述】:

我在 google colab 中运行此代码(我也在本地尝试过)。我只使用一张图片,它使用了所有的内存。我做错了吗?使用 16 GB 内存正常吗?我添加了 %matplotlib inline 仍然崩溃?

import cv2
import matplotlib.pyplot as plt
import numpy as np 

f = cv2.imread('/content/gdrive/MyDrive/grass.png')
f = cv2.cvtColor(f, cv2.COLOR_BGR2GRAY).astype(float)

plt.imshow(f)
plt.colorbar()

def gauss1(sigma, width):
    
    hwidth = round((width-1)/2)
    x = np.arange(-hwidth, hwidth+1,1)
    
    g = np.exp(-x**2/(2*sigma**2))
    return g/np.sum(g)
    
    
g1=gauss1(2,11)
g1=np.reshape(g1,(1,-1))
plt.imshow(g1)

f1 = cv2.filter2D(f,-1,g1)
fig = plt.figure(figsize=(10, 20))
fig.add_subplot(1,2,1)
plt.imshow(f)
fig.add_subplot(1,2,2)
plt.imshow(f1)

它甚至不产生最后一个代码 sn-p 的输出。

【问题讨论】:

  • 使用plt.show() 输出或%matplotlib inline 如果您使用的是jupyter notebook 环境。
  • 这也能解决colab的问题吗
  • 是的,在导入后添加%matplotlib inline,因为 colab 是笔记本环境,它会显示输出。
  • 否则,如果您只需要显示plt.show(),则可以在代码块的末尾添加plt.show()%matplotlib inline 适用于整个笔记本。
  • 我添加了 %matplotlib inline 但它仍然崩溃

标签: python python-3.x numpy opencv image-processing


【解决方案1】:

用途:

  • 如果您使用终端/控制台,请使用 plt.show() 显示 matplotlib 输出。
  • 如果您使用任何 ipython 笔记本内核(例如 jupyter notebook、google colab 或 kaggle notebook),请使用 %matplotlib inline

【讨论】:

  • 我添加了 %matplotlib inline 但它仍然崩溃
  • 这应该是评论,而不是答案。
  • 结帐this。它工作正常。检查您的图像是否有效。我使用了计算机中的本地图像。
  • 0.78 GB,我建议您重新启动运行时并重试。你试过我分享的笔记本吗?你可以运行它,看看它是如何工作的。
  • 告诉你它工作正常。始终尝试使用其他输入来交叉检查您是否有问题。乐于助人!
猜你喜欢
  • 1970-01-01
  • 2022-01-24
  • 2013-09-25
  • 1970-01-01
  • 2018-10-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多