tico
August 12, 2019, 11:29am
4
@yongwww @srkreddy1238 @vinx13 Any ideas about this?
The only way that I was able to properly compile my model with CropAndResize was to remove the following assertion.
from .common import AttrCvt, get_relay_op
from .common import infer_type as _infer_type
from .common import infer_shape as _infer_shape
from .common import infer_channels as _infer_channels
__all__ = ['from_tensorflow']
def _infer_value(input_val, params):
from tvm.contrib import graph_runtime
# Check that all free variables have associated parameters.
assert all(var.name_hint in params.keys() for var in analysis.free_vars(
input_val)), "All inputs to infer must be available in params."
func = _expr.Function(analysis.free_vars(input_val), input_val)
with tvm.relay.build_config(opt_level=0):
graph, lib, params = tvm.relay.build(func, target="llvm", params=params)
ctx = tvm.context("llvm", 0)
m = graph_runtime.create(graph, lib, ctx)
m.set_input(**params)
m.run()
return m.get_output(0)
The test case located at test_forward.py works since all inputs given are constants. As soon as you use a Placeholder or another operator as input then you hit the error mentioned above.
def test_forward_crop():
""" Crop to bounding box """
_test_crop((1, 224, 224, 3), 20, 20, 120, 120)
#######################################################################
# CropAndResize
# -------------
def _test_forward_crop_and_resize(img_shape, boxes, box_idx, crop_size, method='bilinear', dtype="float32"):
image = np.random.uniform(0, 10, size=img_shape).astype(dtype)
tf.reset_default_graph()
in_data = tf.placeholder(dtype, image.shape, name="in_data")
tf.image.crop_and_resize(in_data, boxes=boxes, box_ind=box_idx, crop_size=crop_size,
method=method, name="crop_and_resize")
compare_tf_with_tvm([image], ['in_data:0'], 'crop_and_resize:0')
def test_forward_crop_and_resize():
""" CropAndResize """
_test_forward_crop_and_resize([1, 11, 11, 3], [[0, 0, 1, 1]], [0], [5, 5])
The following is a minimal test model that also fails.
image = tf.placeholder(tf.float32, shape=(1, 24, 42, 64), name='image')
boxes = tf.placeholder(tf.float32, shape=(1, 4), name='boxes')
box_ind = tf.zeros(shape=tf.shape(boxes)[0], dtype=tf.int32)
crop_size = [4, 4]
crop = tf.image.crop_and_resize(image, boxes, box_ind=box_ind, crop_size = crop_size, name='crop')