# cv2.imshow("Output", output)
        # cv2.waitKey(0)


    print("[info] gradCam...")
    pred = np.argmax(prediction)
    cam = GradCAM(model, pred)

    image = np.expand_dims(datas[i], axis=0)
    image = imagenet_utils.preprocess_input(image)
    heatmap = cam.compute_heatmap(datas[i].reshape(1, 180, 180, 3))

    # 결과 히트 맵의 크기를 원래 입력 이미지 크기로 조정 한 다음 이미지 위에 히트 맵을 오버레이
    heatmap = cv2.resize(heatmap, (origs[i].shape[1], origs[i].shape[0]))
    (heatmap, output) = cam.overlay_heatmap(heatmap, origs[i], alpha=0.5)

    # 출력 이미지에 예측 된 레이블을 그립니다.
    cv2.rectangle(output, (0, 0), (340, 40), (0, 0, 0), -1)
    cv2.putText(output, labels[0], (10, 25), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (255, 255, 255), 2)

    # 원본 이미지와 결과로 생성 된 히트 맵 및 출력 이미지를 화면에 표시
    output = np.vstack([origs[i], heatmap, output])
    output = imutils.resize(output, height=700)
    cv2.imshow("Output", output)
    cv2.waitKey(0)





print('[STEP 3] 모델로 데이터 예측하기')
predictions = model.predict(data, batch_size=FLG.BATCH_SIZE)
# (defect_predictions, lacuna_predictions, normal_predictions, spoke_predictions, spot_predictions) =predictions
# print(str(len(defect_predictions)))
print('[STEP 4] 결과 보여주기')

# for i, (defect, lacuna, normal, spoke, spot) in enumerate(zip(defect_predictions, lacuna_predictions, normal_predictions, spoke_predictions, spot_predictions)):
for i, prediction in enumerate(predictions):
    (defect, lacuna, normal, spoke,
     spot) = (prediction[0], prediction[1], prediction[2], prediction[3],
              prediction[4])

    labels = []
    labels.append("{}: {:.2f}%".format('defect', defect * 100))
    labels.append("{}: {:.2f}%".format('lacuna', lacuna * 100))
    labels.append("{}: {:.2f}%".format('normal', normal * 100))
    labels.append("{}: {:.2f}%".format('spoke', spoke * 100))
    labels.append("{}: {:.2f}%".format('spot', spot * 100))

    # draw the label on the image
    green = (0, 255, 0)
    output = imutils.resize(origs[i], width=400)
    y = 300
    for label in labels:
        y = y + 20
        cv2.putText(output, label, (10, y), cv2.FONT_HERSHEY_SIMPLEX, 0.5,
                    green, 1)

    cv2.imshow("Output", output)
    cv2.waitKey(0)