It may seem a frequently asked question, but the thing is that I understand this error, but to get 1251936 with a shape of dimension 2, it would require (1118.89945929024,1118.89945929024) but this number must be an integer, then 1118. Which give 1249924, and that's a problem.
def create_features(img):
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
features, _ = train.create_features(img, img_gray, label=None, train=False)
return features
def compute_prediction(img, model):
border = 5 # (haralick neighbourhood - 1) / 2
img = cv2.copyMakeBorder(img, top=border, bottom=border, \
left=border, right=border, \
borderType = cv2.BORDER_CONSTANT, \
value=[0, 0, 0])
features = create_features(img)
predictions = model.predict(features.reshape(-1, features.shape[1]))
pred_size = int(math.sqrt(features.shape[0]))
inference_img = predictions.reshape(pred_size, pred_size)
return inference_img
def infer_images(image_dir, model_path, output_dir):
filelist = glob(os.path.join(image_dir,'*.png'))
print ('[INFO] Running inference on %s test images' %len(filelist))
model = pkl.load(open( model_path, "rb" ) )
for file in filelist:
print ('[INFO] Processing images:', os.path.basename(file))
inference_img = compute_prediction(cv2.imread(file, 1), model)
cv2.imwrite(os.path.join(output_dir, os.path.basename(file)), inference_img)