日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

NameError: name ‘imshow’ is not defined. 和TypeError: Invalid shape (3, 224, 224) for image data

發布時間:2024/3/26 编程问答 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 NameError: name ‘imshow’ is not defined. 和TypeError: Invalid shape (3, 224, 224) for image data 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
image_path = 'image_06621.jpg' img = process_image(image_path) imshow(img)

上面的代碼是執行對圖像的展示的相關代碼,但是出現了下面的報錯:

NameError: name ‘imshow’ is not defined.

原因是沒有導入matplotlib,在第一行加入:

import matplotlib.pyplot as plt

import matplotlib.pyplot as plt image_path = 'image_06621.jpg' img = process_image(image_path) imshow(img)

?然后又出現了下面的報錯,沒有畫出相應的圖像:

--------------------------------------------------------------------------- TypeError Traceback (most recent call last) ~\AppData\Local\Temp/ipykernel_12484/1515367799.py in <module>2 image_path = 'image_06621.jpg'3 img = process_image(image_path) ----> 4 imshow(img)D:\programfiles\miniconda\envs\py38torch_gpu\lib\site-packages\matplotlib\_api\deprecation.py in wrapper(*args, **kwargs)454 "parameter will become keyword-only %(removal)s.",455 name=name, obj_type=f"parameter of {func.__name__}()") --> 456 return func(*args, **kwargs)457 458 # Don't modify *func*'s signature, as boilerplate.py needs it.D:\programfiles\miniconda\envs\py38torch_gpu\lib\site-packages\matplotlib\pyplot.py in imshow(X, cmap, norm, aspect, interpolation, alpha, vmin, vmax, origin, extent, interpolation_stage, filternorm, filterrad, resample, url, data, **kwargs)2638 interpolation_stage=None, filternorm=True, filterrad=4.0,2639 resample=None, url=None, data=None, **kwargs): -> 2640 __ret = gca().imshow(2641 X, cmap=cmap, norm=norm, aspect=aspect,2642 interpolation=interpolation, alpha=alpha, vmin=vmin,D:\programfiles\miniconda\envs\py38torch_gpu\lib\site-packages\matplotlib\_api\deprecation.py in wrapper(*args, **kwargs)454 "parameter will become keyword-only %(removal)s.",455 name=name, obj_type=f"parameter of {func.__name__}()") --> 456 return func(*args, **kwargs)457 458 # Don't modify *func*'s signature, as boilerplate.py needs it.D:\programfiles\miniconda\envs\py38torch_gpu\lib\site-packages\matplotlib\__init__.py in inner(ax, data, *args, **kwargs)1410 def inner(ax, *args, data=None, **kwargs):1411 if data is None: -> 1412 return func(ax, *map(sanitize_sequence, args), **kwargs)1413 1414 bound = new_sig.bind(ax, *args, **kwargs)D:\programfiles\miniconda\envs\py38torch_gpu\lib\site-packages\matplotlib\axes\_axes.py in imshow(self, X, cmap, norm, aspect, interpolation, alpha, vmin, vmax, origin, extent, interpolation_stage, filternorm, filterrad, resample, url, **kwargs)5486 **kwargs)5487 -> 5488 im.set_data(X)5489 im.set_alpha(alpha)5490 if im.get_clip_path() is None:D:\programfiles\miniconda\envs\py38torch_gpu\lib\site-packages\matplotlib\image.py in set_data(self, A)713 if not (self._A.ndim == 2714 or self._A.ndim == 3 and self._A.shape[-1] in [3, 4]): --> 715 raise TypeError("Invalid shape {} for image data"716 .format(self._A.shape))717 TypeError: Invalid shape (3, 224, 224) for image data

?原因是圖像的矩陣錯誤,錯誤提示了相應的解決辦法,圖像的第三個參數是顏色通道的個數,將其進行轉置后就能畫出相應的圖像

import matplotlib.pyplot as plt image_path = 'image_06621.jpg' img = process_image(image_path) imshow(img.T)

總結

以上是生活随笔為你收集整理的NameError: name ‘imshow’ is not defined. 和TypeError: Invalid shape (3, 224, 224) for image data的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。