gray-scale shift
This commit is contained in:
parent
f77a83fca9
commit
dc6a15c57f
1 changed files with 9 additions and 5 deletions
|
|
@ -102,13 +102,17 @@ class TextProcessor:
|
|||
|
||||
|
||||
def preprocess_image(image_path):
|
||||
img = cv2.imread(image_path)
|
||||
# Load image in grayscale (1-channel)
|
||||
gray = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
|
||||
|
||||
# Convert grayscale to 3-channel RGB by duplicating the gray channel
|
||||
img = cv2.cvtColor(gray, cv2.COLOR_GRAY2RGB)
|
||||
mat_in = ncnn.Mat.from_pixels_resize(
|
||||
img, ncnn.Mat.PixelType.PIXEL_RGB, img.shape[1], img.shape[0], 224, 224
|
||||
)
|
||||
|
||||
mean_vals = [0.5, 0.5, 0.5] * 3
|
||||
norm_vals = [1/255, 1/255, 1/255] * 3
|
||||
mean_vals = [0.5, 0.5, 0.5] * 1
|
||||
norm_vals = [1/255, 1/255, 1/255] * 1
|
||||
mat_in.substract_mean_normalize(mean_vals, norm_vals)
|
||||
return mat_in
|
||||
|
||||
|
|
@ -127,11 +131,11 @@ def run_inference(mat_in, model_path="model"):
|
|||
try:
|
||||
ret, out0 = ex.extract("out0")
|
||||
print("Output shape:", out0.shape)
|
||||
predictions = np.array(out0)
|
||||
predictions = np.squeeze(np.array(out0))
|
||||
# ids = np.argmax(predictions, axis=-1)
|
||||
ids = argmax_last_axis(predictions)
|
||||
print("argmax'ed: ", ids)
|
||||
return np.squeeze(ids)
|
||||
return ids
|
||||
finally:
|
||||
del ex, net
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue