I am running a model from github and I already encountered several errors with pathing etc. After fixing this, I think the main error for now is tensorflow. This repo was probably done when TF 1.x, and now with the change to TF 2, I might need to migrate everything.
Mainly, I get the following error:
@ops.RegisterShape('ApproxMatch')
AttributeError: module 'tensorflow.python.framework.ops' has no attribute 'RegisterShape'
in:
import tensorflow as tf
from tensorflow.python.framework import ops
import os.path as osp
base_dir = osp.dirname(osp.abspath(__file__))
approxmatch_module = tf.load_op_library(osp.join(base_dir, 'tf_approxmatch_so.so'))
def approx_match(xyz1,xyz2):
'''
input:
xyz1 : batch_size * #dataset_points * 3
xyz2 : batch_size * #query_points * 3
returns:
match : batch_size * #query_points * #dataset_points
'''
return approxmatch_module.approx_match(xyz1,xyz2)
ops.NoGradient('ApproxMatch')
#@tf.RegisterShape('ApproxMatch')
@ops.RegisterShape('ApproxMatch')
def _approx_match_shape(op):
shape1=op.inputs[0].get_shape().with_rank(3)
shape2=op.inputs[1].get_shape().with_rank(3)
return [tf.TensorShape([shape1.dims[0],shape2.dims[1],shape1.dims[1]])]
2 main things I am not understanding:
- I read that this probably will make me have to create the
opsC++ routines but at the same time, I can see that these are done in here:@ops.RegisterShape('ApproxMatch'). Like this and this withREGISTER_OP(...).SetShapeFn(...). But I dont think I am understanding the process and have seen other questions with the same, but no real implementation/answer. - If I go to the location of the tf_approxmatch shared library (
approxmatch_module = tf.load_op_library(osp.join(base_dir, 'tf_approxmatch_so.so'))), I cannot open it or edit it withgedit, so I am assuming I am not supposed to change anything in there (?).
There are py, cpp and cu files in that folder (I already did make yesterday and everything ran smoothly).
__init__.py tf_approxmatch.cu.o tf_nndistance.cu.o
makefile tf_approxmatch.py tf_nndistance.py
__pycache__ tf_approxmatch_so.so tf_nndistance_so.so
tf_approxmatch.cpp tf_nndistance.cpp
tf_approxmatch.cu tf_nndistance.cu
My main guess is that I should register the operation of RegisterShape somehow in the cpp file as it already has some registered ops, but I am a bit lost because I am not even sure if I am understanding the problem I have. I will just show the first lines of the file:
#include "tensorflow/core/framework/op.h"
#include "tensorflow/core/framework/op_kernel.h"
#include <algorithm>
#include <vector>
#include <math.h>
using namespace tensorflow;
REGISTER_OP("ApproxMatch")
.Input("xyz1: float32")
.Input("xyz2: float32")
.Output("match: float32");
REGISTER_OP("MatchCost")
.Input("xyz1: float32")
.Input("xyz2: float32")
.Input("match: float32")
.Output("cost: float32");
REGISTER_OP("MatchCostGrad")
.Input("xyz1: float32")
.Input("xyz2: float32")
.Input("match: float32")
.Output("grad1: float32")
.Output("grad2: float32");