使用 keras load_img 函数时,matplotlib as plt 不起作用
While using keras load_img function, matplotlib as plt doesn't function
我一直在做这个图像分类(水印检测)作业
我正在尝试加载图像文件夹
from keras.preprocessing.image import load_img
import cv2
import matplotlib.pyplot as plt
DATADIR = 'F:\IMP.DATA\Task\Watermark_test_data'
CATEGORIES=['Watermark','No Watermark']
for category in CATEGORIES:
path= os.path.join(DATADIR,category)#path to test folder
for img in os.listdir(path):
img_array = cv2.imread(os.path.dirname(os.path.join(path,img), cv2.IMREAD_GRAYSCALE)
plt.imshow(img_array,cmap="gray")
plt.show(img_array)
break
break
img = load_img('F:/IMP.DATA/Task/Watermark_test_data/Watermark/1.jpg')
print(type(img))
print(img.format)
print(img.mode)
print(img.size)
img.show()
import numpy as np
import matplotlib.pyplot as plt
from keras.models import Sequential
from keras.layers import Dense,Dropout,Flatten
from keras.layers.convolutional import Conv2D,MaxPooling2D
from keras.utils import np_utils
from keras import backend as K
import os
import cv2
DATADIR = 'F:\IMP.DATA\Task\Watermark_test_data'
CATEGORIES=['Watermark','No Watermark']
for category in CATEGORIES:
path= os.path.join(DATADIR,category)#path to test folder
for img in os.listdir(path):
img_array = cv2.imread(os.path.dirname(os.path.join(path,img), cv2.IMREAD_GRAYSCALE)
plt.imshow(img_array,cmap="gray")
plt.show(img_array)
break
break
我一直在使用 cv2 和 load_img 来加载图像,但在这两种情况下,我都在 matplotlib 中遇到错误
plt.imshow(函数)
这是我得到的错误
File "<ipython-input-51-2b07cb64d5a1>", line 11
plt.imshow(img_array,cmap="gray")
^
SyntaxError: invalid syntax
我看不出语法有什么问题
SyntaxError
是由于此行中缺少右括号引起的:
img_array = cv2.imread(os.path.dirname(os.path.join(path,img), cv2.IMREAD_GRAYSCALE)
在os.path.dirname(os.path.join(path,img)
后加上)
即可解决
我一直在做这个图像分类(水印检测)作业 我正在尝试加载图像文件夹
from keras.preprocessing.image import load_img
import cv2
import matplotlib.pyplot as plt
DATADIR = 'F:\IMP.DATA\Task\Watermark_test_data'
CATEGORIES=['Watermark','No Watermark']
for category in CATEGORIES:
path= os.path.join(DATADIR,category)#path to test folder
for img in os.listdir(path):
img_array = cv2.imread(os.path.dirname(os.path.join(path,img), cv2.IMREAD_GRAYSCALE)
plt.imshow(img_array,cmap="gray")
plt.show(img_array)
break
break
img = load_img('F:/IMP.DATA/Task/Watermark_test_data/Watermark/1.jpg')
print(type(img))
print(img.format)
print(img.mode)
print(img.size)
img.show()
import numpy as np
import matplotlib.pyplot as plt
from keras.models import Sequential
from keras.layers import Dense,Dropout,Flatten
from keras.layers.convolutional import Conv2D,MaxPooling2D
from keras.utils import np_utils
from keras import backend as K
import os
import cv2
DATADIR = 'F:\IMP.DATA\Task\Watermark_test_data'
CATEGORIES=['Watermark','No Watermark']
for category in CATEGORIES:
path= os.path.join(DATADIR,category)#path to test folder
for img in os.listdir(path):
img_array = cv2.imread(os.path.dirname(os.path.join(path,img), cv2.IMREAD_GRAYSCALE)
plt.imshow(img_array,cmap="gray")
plt.show(img_array)
break
break
我一直在使用 cv2 和 load_img 来加载图像,但在这两种情况下,我都在 matplotlib 中遇到错误 plt.imshow(函数) 这是我得到的错误
File "<ipython-input-51-2b07cb64d5a1>", line 11
plt.imshow(img_array,cmap="gray")
^
SyntaxError: invalid syntax
我看不出语法有什么问题
SyntaxError
是由于此行中缺少右括号引起的:
img_array = cv2.imread(os.path.dirname(os.path.join(path,img), cv2.IMREAD_GRAYSCALE)
在os.path.dirname(os.path.join(path,img)
后加上)
即可解决