如何在张量流中创建具体函数以获取语义分割图像并计算坐标。
我们具有与要在tflite文件中转换以用于移动应用程序相同但没有具体功能的当前代码。
def predict_new_image(img_path, model):
img = load_img(img_path, grayscale=True)
x_img = img_to_array(img)
x_img = resize(x_img, (128, 128, 1), mode='constant', preserve_range=True)
X = np.zeros((1, 128, 128, 1), dtype=np.float32)
y_img = np.zeros((1, 128, 128, 1), dtype=np.float32)
X[0, ..., 0] = x_img.squeeze() / 255
pred = model.predict(X)
preds_img = (pred > 0.5).astype(np.uint8)
img_arr = preds_img[:,:,0]
# get the coordinates where the pixel isn't white (at a threshold)
black_thres = 1
idx = [(i,j) for i,x in enumerate(img_arr) for j,y in enumerate(x) if img_arr[i,j]==black_thres]
return idx