내 모델은 cifar10 데이터 세트 에서 훈련되었습니다.
내 컨볼 루션 레이어는 numpy 배열에 대해 (None, 3, 32, 32) 인 32, 32 입력을 기대 합니다. 하지만 이미지 모양을 바꾸려고 할 때
이미지 = load_img (인수 [ "이미지"], target_size = inputShape)
나는 (1, 32, 32, 3) 모양을 얻고 있습니다. 그래서 무슨 일이 일어나고 있습니까?
from keras.models
import load_model
from keras.applications
import imagenet_utils
from keras.preprocessing.image
import img_to_array, load_img
from keras
import backend as K
import numpy as np
import argparse
import cv2
seed = 7
numpy.random.seed(seed)
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required = True,
help = "Path tp the input image")
args = vars(ap.parse_args())
inputShape = (32, 32)
preprocess = imagenet_utils.preprocess_input
model = load_model('cifar.h5')
print("[INFO]: loading and pre-processing image...")
image = load_img(args["image"], target_size = inputShape)
image = image_to_array(image)
print image.shape
image = np.expand_dims(image, axis = 0)
image = preprocess(image)
print("[INFO]: classifying image")
preds = model.predict(image)
P = imagenet_utils.decode_predictions(preds)
for (i, (imagenetID, label, prob)) in enumerate(P[0]):
(imagenetID, label, prob) = P[0][0]
print("{}. {}: {:.2f}%".format(i + 1, label, prob * 100))
orig = cv2.imread(args["image"])
cv2.putText(orig, "Label: {}, {:.2f}%".format(label, prob * 100), (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 0, 255), 2)
cv2.imshow("Classification", orig)
cv2.waitKey(0)
줄만 추가
image = image.copy().transpose((2,0,1))
image = image_to_array(image)
줄 뒤
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다