plaidml / onnx-plaidml

An ONNX backend using PlaidML
GNU Affero General Public License v3.0
28 stars 8 forks source link

Version-10 not supported #20

Open samhodge opened 5 years ago

samhodge commented 5 years ago

I got the following error

(tensorflow-1.12.0-src) kaos-new:plaid-maskrcnn sam$ python dirty.py 
Traceback (most recent call last):
  File "dirty.py", line 49, in <module>
    rep = onnx_plaidml.backend.prepare(model, device='GPU')
  File "/Users/sam/dev/virtualenv/tensorflow-1.12.0-src/lib/python3.6/site-packages/onnx_plaidml/backend.py", line 249, in prepare
    ops = _load_ops(model.opset_import)
  File "/Users/sam/dev/virtualenv/tensorflow-1.12.0-src/lib/python3.6/site-packages/onnx_plaidml/backend.py", line 77, in _load_ops
    domain, version)), None)
  File "<string>", line 3, in raise_from
NotImplementedError: ""/version=10" is not implemented by the PlaidML ONNX backend

When running the following test code


import onnx
import onnx_plaidml.backend
import onnx.numpy_helper

data_path = "//Users/sam/dev/plaid-maskrcnn/test_data_set_0/input_0.pb"
tensor = onnx.TensorProto()
with open(data_path, 'rb') as f:
    tensor.ParseFromString(f.read())
x = onnx.numpy_helper.to_array(tensor)
model_path = "/Users/sam/dev/plaid-maskrcnn/mask_rcnn_R_50_FPN_1x.onnx"
model = onnx.load(model_path)

import numpy as np
from PIL import Image

def preprocess(image):
    # Resize
    ratio = 800.0 / min(image.size[0], image.size[1])
    image = image.resize((int(ratio * image.size[0]), int(ratio * image.size[1])), Image.BILINEAR)

    # Convert to BGR
    image = np.array(image)[:, :, [2, 1, 0]].astype('float32')

    # HWC -> CHW
    image = np.transpose(image, [2, 0, 1])

    # Normalize
    mean_vec = np.array([102.9801, 115.9465, 122.7717])
    for i in range(image.shape[0]):
        image[i, :, :] = image[i, :, :] - mean_vec[i]

    # Pad to be divisible of 32
    import math
    padded_h = int(math.ceil(image.shape[1] / 32) * 32)
    padded_w = int(math.ceil(image.shape[2] / 32) * 32)

    padded_image = np.zeros((3, padded_h, padded_w), dtype=np.float32)
    padded_image[:, :image.shape[1], :image.shape[2]] = image
    image = padded_image

    return image

img = Image.open('/Users/sam/Downloads/VER01_010_plateD_v0001.1008.png')
img_data = preprocess(img)

rep = onnx_plaidml.backend.prepare(model, device='GPU')
for batch in range(1):
    data = img['inputs'][batch, :]
    output = rep.run([data])
    print(output)

Just trying to see if it possible to run maskrcnn on plaidml for GPU acceleration on a non NVIDIA GPU.

But it seems that onnx-plaidml is no longer maintained.

samhodge commented 5 years ago

See:

https://github.com/onnx/models/tree/master/mask_rcnn