/
vuron
/
adept
Обзор
Документация
Войти
/
vuron
/
adept
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
python/cpp_bindings/conv2d_py.cpp
58 строк
3 KB
kolkir
Initial ResNet implementation
06 мар 2025, 00:15
06 мар 2025, 00:15
155bcba
Код
Авторство
О чём код?
#include <pybind11/pybind11.h> #include <pybind11/stl.h> #include <adept/nn/conv2d.hpp> #include <sstream> namespace py = pybind11; using namespace adept; namespace { std::shared_ptr<Conv2dImpl> make_conv2d(index_t in_ch, index_t out_ch, const std::vector<index_t>& kernel, const std::vector<index_t>& stride, const std::vector<index_t>& padding, const std::vector<index_t>& dilation, bool bias) { return std::make_shared<Conv2dImpl>(Conv2dOptions(in_ch, out_ch, kernel) .with_stride(stride) .with_padding(padding) .with_dilation(dilation) .with_bias(bias)); } std::shared_ptr<Conv2dImpl> make_conv2d_sv(index_t in_ch, index_t out_ch, index_t kernel, index_t stride, index_t padding, index_t dilation, bool bias) { return std::make_shared<Conv2dImpl>(Conv2dOptions(in_ch, out_ch, kernel) .with_stride(stride) .with_padding(padding) .with_dilation(dilation) .with_bias(bias)); } } // namespace void bind_conv2d(py::module& m) { py::class_<Conv2dImpl, Module, std::shared_ptr<Conv2dImpl>>(m, "Conv2d") .def(py::init(&make_conv2d), py::arg("in_channels"), py::arg("out_channels"), py::arg("kernel"), py::arg("stride") = std::vector<index_t>{1, 1}, py::arg("padding") = std::vector<index_t>{0, 0}, py::arg("dilation") = std::vector<index_t>{1, 1}, py::arg("bias") = true) .def(py::init(&make_conv2d_sv), py::arg("in_channels"), py::arg("out_channels"), py::arg("kernel"), py::arg("stride") = index_t{1}, py::arg("padding") = index_t{0}, py::arg("dilation") = index_t{1}, py::arg("bias") = true) .def("parameters", &Conv2dImpl::parameters) .def("forward", &Conv2dImpl::forward) .def("__call__", [](Conv2dImpl& self, Variable& input) { return self.forward(input); }) .def("__repr__", [](const Conv2dImpl& v) { std::stringstream buf; buf << v; return buf.str(); }); }