# Why isn't tensorflow picking up my custom operator?

**URL:** <https://discuss.ai.google.dev/t/why-isnt-tensorflow-picking-up-my-custom-operator/31786>\
**Category:** General Discussion\
**Tags:** tfcore, python\
**Created:** [July 1, 2024, 3:40am UTC](https://discuss.ai.google.dev/t/why-isnt-tensorflow-picking-up-my-custom-operator/31786 "2024-07-01T03:40:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Idrees](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/idrees/32/9655_2.png) [@Idrees](https://discuss.ai.google.dev/u/Idrees)\
**Post date:** [July 1, 2024, 3:40am UTC](https://discuss.ai.google.dev/t/why-isnt-tensorflow-picking-up-my-custom-operator/31786/1 "2024-07-01T03:40:03Z")

</div>

Hello! I have recently been trying to add a custom operator to tensorflow that requires me to perform a custom build. Unfortunately, I am unable to register the operator and the following error occurs in Python when the operator is requested: `AttributeError: module '012ff3e36e3c24aefc4a3a7b68a03fedd1e7a7e1' has no attribute 'Resample'`

The commands I am using to build tensorflow with the custom operator are the following (in order):

```auto
bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package --local_ram_resources=4096 --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0"

./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg

pip install /tmp/tensorflow_pkg/tensorflow-2.5.3-cp36-cp36m-linux_x86_64.whl

bazel build --config=opt //tensorflow/core/user_ops:Resampler.so --local_ram_resources=6000 --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0"

```

This is after moving the operators into the `tensorflow/tensorflow/core/user_ops` directory along with a Bazel build file that looks like the following:

```auto
load(
    "//tensorflow/core/platform:rules_cc.bzl",
    "cc_library",
)
load(
    "//tensorflow:tensorflow.bzl",
    "tf_copts",
)

package(
    default_visibility = [
        "//tensorflow/core: __pkg__",
    ],
    licenses = ["notice"],
)

cc_library(
    name = "user_ops_op_lib",
    srcs = glob(["*.cc"]),
    hdrs = glob(["*.h"]),
    copts = tf_copts(),
    linkstatic = 1,
    visibility = ["//tensorflow/core: __pkg__"],
    deps = ["//tensorflow/core:framework"],
    alwayslink = 1,
)

load("//tensorflow:tensorflow.bzl", "tf_custom_op_library")

tf_custom_op_library(
    name = "Resampler.so",
   

```

The tensorflow version being targeted is 2.5.x. Note that the custom operator also contains the following registration code within Resampler.cc:

```auto
REGISTER_OP("Resample")
    .Attr("T: {float, int32}")
    .Input("input_image: T")
    .Input("transformation: float")
    .Input("output_size: int32")
    .Output("output_image: T")
...
#define REGISTER_CPU(T) \
    REGISTER_KERNEL_BUILDER( \
        Name("Resample").Device(DEVICE_CPU).TypeConstraint<T>("T"), \
        ResamplerOp<CPUDevice, T>);

```

Oddly enough, it seems that if I then rename the operator function in my code and continue trying to rebuild, sometimes the operator eventually gets registered. But trying again from scratch with the new name does not work making me think that something is wrong with my order of operations here. I have yet to find a reproducible order of events to get the operator to be registered successfully, so any help would be appreciated!

Duplicate Stack Overflow question for reference: [python - Unable to register custom compiled TensorFlow operator - Stack Overflow](https://stackoverflow.com/questions/78681267/why-isnt-tensorflow-picking-up-my-custom-operator-and-returning-a-has-no-attri)

---

<div class="post-metadata">

**Author:** ![Divya\_Sree\_Kayyuri](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/divya_sree_kayyuri/32/29791_2.png) [@Divya\_Sree\_Kayyuri](https://discuss.ai.google.dev/u/Divya_Sree_Kayyuri)\
**Post date:** [July 2, 2025, 7:26am UTC](https://discuss.ai.google.dev/t/why-isnt-tensorflow-picking-up-my-custom-operator/31786/3 "2025-07-02T07:26:21Z")

</div>

Hi @Idrees, Try to clear the Bazel cache with `bazel clean`. And rebuild the pip package and reinstall it. If the error still persists, Please let me know. Thank you!
