json_file = open('model_ImageDataGenerator_myImage.json', 'r')
loaded_model_json = json_file.read()
json_file.close()
model = tf.keras.models.model_from_json(loaded_model_json)
model.load_weights("model_ImageDataGenerator_myImage.h5")
model.compile(loss=tf.keras.losses.categorical_crossentropy,
optimizer=tf.keras.optimizers.Adadelta(),
metrics=['accuracy'])
model.summary()
opt1 = tf.keras.optimizers.Adam(lr=0.001)
model.compile(
optimizer='adam',
loss='categorical_crossentropy',
metrics=['accuracy'])
img = cv2.imread('F:/1100317_rotate/glue/IMG_4871.bmp')
w=200
h=200
X=[]
img = cv2.resize(img, (w,h), interpolation=cv2.INTER_AREA)
img=img.reshape(w,h,3)
img = img.astype('uint8')
img = cv2.resize(img, (200, 200), interpolation=cv2.INTER_AREA)
im_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
X.append(im_rgb)
X = np.asarray(X)
X = X.astype('float32')
X=X/255
X=X.reshape(X.shape[0],w,h,3);
predict = model.predict(X)
想詢問一下
ValueError: Input 0 of layer dense is incompatible with the layer: expected axis -1 of input shape to have value 960000 but received input with shape [None, 1280000]
不太懂哪邊資料錯誤
模組使用訓練圖片之預處理為
X=[]
Y=[]
print(dirs);
w=200 # 1000
h=200 # 1000
i=0
for name in dirs:
#file_paths = glob.glob(path.join(IMAGEPATH+"/"+name, '.'))
file_paths = glob.glob(path.join(IMAGEPATH,name))
file_name = os.listdir(file_paths[0])
for path3 in file_name :
print(path.join(file_paths[0], path3))
img = cv2.imread(path3)
img = cv2.imread(path.join(file_paths[0], path3))
if img is not None:
img = cv2.resize(img, (w,h), interpolation=cv2.INTER_AREA)
im_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
X.append(im_rgb)
Y.append(i)
i=i+1
print(path3)
X = np.asarray(X)
Y = np.asarray(Y)
print(X)
print(Y)
print("+++++++++Done reading!!+++++++++")
X = X.astype('float32')
X=X/255
X=X.reshape(X.shape[0],w,h,3);
是以相同影像處理方式做預處理
為何無法判別呢
X=X.reshape(X.shape[0],w,h,3)
我想啟另一個話題:
Hi, I code so I am. 我剛去看過你寫的文章,你是神人等級了。
(我拍拍手表示認同)
Model: "sequential"
Layer (type) Output Shape Param #
conv2d (Conv2D) (None, 200, 150, 32) 896
已改成原本第一層維度的條件下
w=200
h=150
img = cv2.resize(img, (w,h), interpolation=cv2.INTER_AREA)
img = img.reshape((1,w,h,32))
predict = model.predict(img)
cv2.imshow('image', predict)
cv2.waitKey(0)
cv2.destroyAllWindows()
i = np.argmax(img[0])
str1 = dirs[i] + " " + str(im_bgr[0][i])
print(str1);
img = cv2.putText(im_bgr,str1, (30,50), cv2.FONT_HERSHEY_SIMPLEX, 1, (255,0, 0), 1, cv2.LINE_AA)
cv2.imshow('image', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
想問一下改成這樣但卻執行程式毫無反應
預想為會顯示出圖形並上字幕為預測%數