question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I have installed with plugin successfully, but I can not use 'interpolate' operation?

See original GitHub issue

I have installed this repo with plugins, but when I issue torch2trt.CONVERTERS.keys(): image

there is no interpolate layer, and when I convert a model with interpolate, it complains ‘AttributeError: ‘Tensor’ object has no attribute ‘_trt’’ before ‘interpolate’ operation, so what’s wrong is here?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
binzh93commented, Jul 31, 2019

when I test the ‘interpolate’ plugin and run notebooks/image_segmentation/conversion.ipynb ,I got this error 1 2 3 my tensorrt version: TensorRT-5.1.5.0.Ubuntu-16.04.5.x86_64-gnu.cuda-9.0.cudnn7.5 python3.5 When I run : python3 -m torch2trt.test --name=interpolate I got nothing info. @jaybdub

0reactions
sonackcommented, Aug 2, 2019

@jaybdub FYI, this issue may be the same as #20 image

I sucessfully install interpolate plugin and import torch2trt with no bug, but when I use “python3 -m torch2trt.test --name=interpolate”, “IndexError: list index out of range” error occured. Do you sovle it ?Change the protobuf version?

My protobuf version is 3.0.0 torch version 1.1.0 torchvision version 0.3 @sonack

My protobuf version is 3.9.0, one thing to note is to add -L${YOUR_PROTOBUF_LIB_PATH} to rule link of build.py, below is my build.py and setup.py, FYI.

build.py

import imp
import subprocess
import os
from string import Template

PLUGINS = [
    'interpolate',
]

BASE_FOLDER = 'torch2trt/converters'

NINJA_TEMPLATE = Template((
    "rule link\n"
    "  command = g++ -shared -o $$out $$in -L{{YOUR PROTOBUF INSTALL DIR}}/lib -L$torch_dir/lib -L$cuda_dir/lib64 -L$trt_lib_dir -lc10 -lc10_cuda -ltorch -lcudart -lcaffe2 -lcaffe2_gpu -lprotobuf -lprotobuf-lite -pthread -lpthread -lnvinfer -Xlinker --unresolved-symbols=ignore-in-shared-libs\n"
    "rule protoc\n"
    "  command = protoc $$in --cpp_out=. --python_out=.\n"
    "rule cxx\n"
    "  command = g++ -c -fPIC $$in -I$cuda_dir/include -I$torch_dir/include -I$torch_dir/include/torch/csrc/api/include -I. -std=c++11 -I$trt_inc_dir\n"
))

PLUGIN_TEMPLATE = Template((
    "build $plugin_dir/$plugin.pb.h $plugin_dir/$plugin.pb.cc $plugin_dir/${plugin}_pb2.py: protoc $plugin_dir/$plugin.proto\n"
    "build $plugin.pb.o: cxx $plugin_dir/$plugin.pb.cc\n"
    "build $plugin.o: cxx $plugin_dir/$plugin.cpp\n"
))


def build(cuda_dir="/usr/local/cuda",
          torch_dir=imp.find_module('torch')[1],
          trt_inc_dir="/usr/include/aarch64-linux-gnu",
          trt_lib_dir="/usr/lib/aarch64-linux-gnu"):

    global PLUGINS, BASE_FOLDER, NINJA_TEMPLATE, PLUGIN_TEMPLATE

    NINJA_STR = NINJA_TEMPLATE.substitute({
        'torch_dir': torch_dir,
        'cuda_dir': cuda_dir,
        'trt_inc_dir': trt_inc_dir,
        'trt_lib_dir': trt_lib_dir,
    })

    plugin_o_files = []
    for plugin in PLUGINS:
        NINJA_STR += \
            PLUGIN_TEMPLATE.substitute({
                'plugin': plugin,
                'plugin_dir': os.path.join(BASE_FOLDER, plugin),
            })
        plugin_o_files += [plugin + '.pb.o', plugin + '.o']

    NINJA_STR += Template((
        "build torch2trt/libtorch2trt.so: link $o_files\n"
    )).substitute({'o_files': ' '.join(plugin_o_files)})

    with open('build.ninja', 'w') as f:
        f.write(NINJA_STR)

    subprocess.call(['ninja'])


if __name__ == '__main__':
    build()

Note to replace {{}} with your own path!!!

setup.py

import os
import glob
import shutil
from setuptools import setup, find_packages
from setuptools.command.install import install
from setuptools.command.develop import develop
from distutils.cmd import Command
from build import build

package_data = {}

plugins_user_options = [
    ('plugins', None, 'Build plugins'),
    ('cuda-dir=', None, 'Location of CUDA (if not default location)'),
    ('torch-dir=', None, 'Location of PyTorch (if not default location)'),
    ('trt-inc-dir=', None, 'Location of TensorRT include files (if not default location)'),
    ('trt-lib-dir=', None, 'Location of TensorRT libraries (if not default location)'),
]


def initialize_plugins_options(cmd_obj):
    cmd_obj.plugins = False
    cmd_obj.cuda_dir = None
    cmd_obj.torch_dir = None
    cmd_obj.trt_inc_dir = None
    cmd_obj.trt_lib_dir = None


def run_plugins_compilation(cmd_obj):
    if cmd_obj.plugins:
        build_args = {}
        if cmd_obj.cuda_dir:
            build_args['cuda_dir'] = cmd_obj.cuda_dir
        if cmd_obj.torch_dir:
            build_args['torch_dir'] = cmd_obj.torch_dir
        if cmd_obj.trt_inc_dir:
            build_args['trt_inc_dir'] = cmd_obj.trt_inc_dir
        if cmd_obj.trt_lib_dir:
            build_args['trt_lib_dir'] = cmd_obj.trt_lib_dir

        print('Building in plugin support')
        build(**build_args)
        package_data['torch2trt'] = ['libtorch2trt.so']


class DevelopCommand(develop):
    description = "Builds the package and symlinks it into the PYTHONPATH"
    user_options = develop.user_options + plugins_user_options

    def initialize_options(self):
        develop.initialize_options(self)
        initialize_plugins_options(self)

    def finalize_options(self):
        develop.finalize_options(self)

    def run(self):
        run_plugins_compilation(self)
        develop.run(self)


class InstallCommand(install):
    description = "Builds the package"
    user_options = install.user_options + plugins_user_options

    def initialize_options(self):
        install.initialize_options(self)
        initialize_plugins_options(self)

    def finalize_options(self):
        install.finalize_options(self)

    def run(self):
        run_plugins_compilation(self)
        install.run(self)


class CleanCommand(Command):
    """Custom clean command to tidy up the project root."""
    PY_CLEAN_FILES = ['./build', './dist', './__pycache__', './*.pyc', './*.tgz', './*.egg-info']
    description = "Command to tidy up the project root"
    user_options = []

    def initialize_options(self):
        pass

    def finalize_options(self):
        pass

    def run(self):
        root_dir = os.path.dirname(os.path.realpath(__file__))
        for path_spec in self.PY_CLEAN_FILES:
            # Make paths absolute and relative to this path
            abs_paths = glob.glob(os.path.normpath(os.path.join(root_dir, path_spec)))
            for path in [str(p) for p in abs_paths]:
                if not path.startswith(root_dir):
                    # Die if path in CLEAN_FILES is absolute + outside this directory
                    raise ValueError("%s is not a path inside %s" % (path, root_dir))
                print('Removing %s' % os.path.relpath(path))
                shutil.rmtree(path)

        cmd_list = {
            "Removing generated protobuf cc files": "find . -name '*.pb.cc' -print0 | xargs -0 rm -f;",
            "Removing generated protobuf h files": "find . -name '*.pb.h' -print0 | xargs -0 rm -f;",
            "Removing generated protobuf py files": "find . -name '*_pb2.py' -print0 | xargs -0 rm -f;",
            "Removing generated ninja files": "find . -name '*.ninja*' -print0 | xargs -0 rm -f;",
            "Removing generated o files": "find . -name '*.o' -print0 | xargs -0 rm -f;",
            "Removing generated so files": "find . -name '*.so' -print0 | xargs -0 rm -f;",
        }

        for cmd, script in cmd_list.items():
            print("{}".format(cmd))
            os.system(script)


setup(
    name='torch2trt',
    version='0.0.0',
    description='An easy to use PyTorch to TensorRT converter',
    cmdclass={
        'install': InstallCommand,
        'clean': CleanCommand,
        'develop': DevelopCommand,
    },
    packages=find_packages(),
    package_data=package_data
)
#!/usr/bin/env bash
python setup.py install --plugins --cuda-dir=/usr/local/cuda-10.0 --trt-inc-dir=/data00/xxx/TensorRT/1404/TensorRT-5.1.5.0/include --trt-lib-dir=/data00/xxx/TensorRT/1404/TensorRT-5.1.5.0/lib 

replace with your own path.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TIN Interpolation QGIS 3.0 - Cell Size - GIS Stack Exchange
The problem was that the Advanced viewshed plugin assumes that cells are square, irrespective of projection being used. I don't see the Advanced ......
Read more >
Interpolating Point Data - QGIS Tutorials and Tips
Make sure you have the Interpolation plugin enabled. See Using Plugins for how to enable plugins. Once enabled, go to Raster ‣ Interpolation...
Read more >
Accessing event data and fields | Logstash Reference [8.5]
A Logstash pipeline usually has three stages: inputs → filters → outputs. Inputs generate events, filters modify them, and outputs ship them elsewhere....
Read more >
ImageJ Macro Language Programmer's Reference Guide v1 ...
To install this tool, open an editor window (Plugins>Macros>New), paste in the macro, then use the editor's. Macros>Install Macros command. Put this macro...
Read more >
Docker Compose release notes
Fixed compose#9897; Compose doesn't stop the pull command for images that can be ... Applied newly loaded environment variables to DockerCli and APIClient...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found