(ASK) Keras Sliding Window Python Image Classification -
i've problem.. how connect keras , sliding window? i've trained model called 'model1' want use in sliding window detect objects.
any suggestion? thanks
img = cv2.imread('frame.jpg', cv2.imread_grayscale) window_sizes = [150,150] json_file = open('motordewa.json', 'r') loaded_model_from_json = json_file.read() json_file.close() loaded_model = model_from_json(loaded_model_from_json) loaded_model.load_weights("motordewa.h5") def find_obj(img, predict_function, step=150, window_sizes=window_sizes): boxonezero = 0 win_size in window_sizes: top in range(0,img.shape[0] - win_size + 1, step): left in range(0, img.shape[1] - win_size + 1, step): box = (top, left, top + win_size, left + win_size) cropped_img = img[box[0]:box[2], box[1]:box[3]] cropped_img = np.array(cropped_img).reshape((1,1,150,150)) print('predicting %r' % (box, )) boxonezero = predict_function(cropped_img) if boxonezero == 1: cropped_img.save('save'+file+'jpeg') boxonezero = box def predict_function(x): result = loaded_model.predict(x) result = result[0] if result==1: return 1 else: return 0 findobj = find_obj(img,predict_function)
the error i've found:
traceback (most recent call last): file "d:\stephen\stts\tensorflow\videoext\sliding-window 2\sliding-window\sliding_window coba.py", line 53, in findmotor = find_motor(img,predict_function) file "d:\stephen\stts\tensorflow\videoext\sliding-window 2\sliding-window\sliding_window coba.py", line 39, in find_motor boxonezero = predict_function(cropped_img) file "d:\stephen\stts\tensorflow\videoext\sliding-window 2\sliding-window\sliding_window coba.py", line 48, in predict_function if result==1: valueerror: truth value of array more 1 element ambiguous. use a.any() or a.all()
Comments
Post a Comment