0

I have to compile Locally Aware NMS (lanms) in my remote server LINUX based with an user account without root access.

In lanms there is a script named adapter.cpp , I have to convert it to .pyd so that it works with python. I have given the code described here.

#include "pybind11/pybind11.h"
#include "pybind11/numpy.h"
#include "pybind11/stl.h"
#include "pybind11/stl_bind.h"

#include "lanms.h"

namespace py = pybind11;


namespace lanms_adaptor {

std::vector<std::vector<float>> polys2floats(const std::vector<lanms::Polygon> &polys) {
    std::vector<std::vector<float>> ret;
    for (size_t i = 0; i < polys.size(); i ++) {
        auto &p = polys[i];
        auto &poly = p.poly;
        ret.emplace_back(std::vector<float>{
                float(poly[0].X), float(poly[0].Y),
                float(poly[1].X), float(poly[1].Y),
                float(poly[2].X), float(poly[2].Y),
                float(poly[3].X), float(poly[3].Y),
                float(p.score),
                });
    }

    return ret;
}


/**
 *
 * \param quad_n9 an n-by-9 numpy array, where first 8 numbers denote the
 *      quadrangle, and the last one is the score
 * \param iou_threshold two quadrangles with iou score above this threshold
 *      will be merged
 *
 * \return an n-by-9 numpy array, the merged quadrangles
 */
std::vector<std::vector<float>> merge_quadrangle_n9(
        py::array_t<float, py::array::c_style | py::array::forcecast> quad_n9,
        float iou_threshold) {
    auto pbuf = quad_n9.request();
    if (pbuf.ndim != 2 || pbuf.shape[1] != 9)
        throw std::runtime_error("quadrangles must have a shape of (n, 9)");
    auto n = pbuf.shape[0];
    auto ptr = static_cast<float *>(pbuf.ptr);
    return polys2floats(lanms::merge_quadrangle_n9(ptr, n, iou_threshold));
  }

 }

PYBIND11_PLUGIN(adaptor) {
py::module m("adaptor", "NMS");

m.def("merge_quadrangle_n9", &lanms_adaptor::merge_quadrangle_n9,
        "merge quadrangels");

return m.ptr();
}

To convert it I have used the following command.

cl adaptor.cpp ./include/clipper/clipper.cpp /I ./include /I "C:\ProgramData\Anaconda3\include" /LD /Fe:adaptor.pyd /link/LIBPATH:"C:\ProgramData\Anaconda3\libs"

It shows an error:

Command 'cl' not found, but can be installed with:

apt install cl-launch

Please ask your administrator.

Furthermore, I don't have the root access. Is there any other way to install "cl" without administrator privileges?

The other way to compile lanms is need to install the g++ compiler in order to compile the adaptar.cpp file.

sudo apt-get install build-essential

It is also asking for the administrator privileges.

3
  • 2
    cl is the visual studio compiler, you probably don't need that. cl-launch is shell wrapper for Common Lisp Feb 15, 2022 at 11:17
  • just to be sure as it is not entirely clear from the question: have you checked whether gcc available on this system?
    – asu
    Feb 15, 2022 at 13:17
  • if not - if you have python and pip available, you should able to install pip packages using the --user flag. conveniently, there exist a few packages on PyPI that allow compiling C++ code, namely, zig: pypi.org/project/ziglang
    – asu
    Feb 15, 2022 at 13:19

1 Answer 1

1

I'm afraid, that it is almost impossible to compile your code on a machine that doesn't have a compiler installed.

The best option, that I can come up with, would be to set up a virtual machine, that runs the same version of the same linux distribution as the server. In that virtual machine, you have root access and can install a compiler. After compiling the code you just copy the program/library to the server. It is however not guaranteed, that the program compiled in the virtual machine will run without problems on the real server.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.