0
テンソルフローを使用してスライディングウィンドウのコードを実行しています。画像オーダーテンソルフロー
これはTheanoのためです。そのため、画像サイズの注文に誤りがあります。
誰も私にテンソルフローの修正方法を教えてもらえますか?
エラー:
とValueError:チェックエラー:予想INPUT_2する形状を有するように(なし、224、224、3)が、形状を持つ配列(1、3、224、224)を得た
image=load_img('\e.jpg')
image= np.array(image).reshape((3264,5896,3))
image = image.astype('float32')
image /= 255
plt.imshow(image)
print(image.shape)
#%%SLIDING WINDOW
''
def find_a_object(image, step=224, window_sizes=[224]):
boxCrack = 0
locations = []
for win_size in window_sizes:
#top = Y, left = X
for Y in range(0, image.shape[0] - win_size + 1, step):
for X in range(0, image.shape[1] - win_size + 1, step):
# compute the (top, left, bottom, right) of the bounding box
box = (Y, X, Y + win_size, X + win_size)
#crop original image
cropped_img = image[box[0]:box[2], box[1]:box[3]]
#reshape cropped image by window
cropped_img = np.array(cropped_img).reshape((1,3,224,224))
boxCrack = predict_function(cropped_img)
if boxCrack ==0:
#print('box classified as crack')
#save location of it
locations.append(box)
print("found")
return locations
#%%FUNCTIONS
def predict_function(x):
result = model.predict_classes(x)
if result==0:
return 0
else:
return 1
##SHOW CROPPED IMAGE
#def show_image(im):
# plt.imshow(im.reshape((100,100,3)))
)
#DRAW BOXES FROM LOCATIONS when classified
def draw_boxes(image, locations):
fix,ax = plt.subplots(1)
ax.imshow(image)
for l in locations:
print (l)
rectR = patches.Rectangle((l[1],l[0]),224,224,linewidth=1,edgecolor='R',facecolor='none'
ax.add_patch(rectR)
#%%get locations from image
locations = find_a_object(image)
draw_boxes(image,locations)
お返事ありがとうございます。今度はエラーが発生します: ValueError:複数の要素を持つ配列の真理値はあいまいです。 a.any()またはa.all()を使用する これを解決する方法はありますか? –
どの行がエラーをスローしますか? –
locations = find_a_object(image)。その行を実行すると、エラーが発生します。 –