/
vuron
/
adept
Обзор
Документация
Войти
/
vuron
/
adept
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
with_cpu
python/cpp_bindings/avgpool2d_py.cpp
40 строк
2 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/avgpool2d.hpp> #include <sstream> namespace py = pybind11; using namespace adept; namespace { std::shared_ptr<AvgPool2dImpl> make_avgpool2d(const std::vector<index_t>& kernel, const std::vector<index_t>& stride, const std::vector<index_t>& padding) { return std::make_shared<AvgPool2dImpl>( AvgPool2dOptions(kernel).with_stride(stride).with_padding(padding)); } std::shared_ptr<AvgPool2dImpl> make_avgpool2d_sv(index_t kernel, index_t stride, index_t padding) { return std::make_shared<AvgPool2dImpl>( AvgPool2dOptions(kernel).with_stride(stride).with_padding(padding)); } } // namespace void bind_avgpool2d(py::module& m) { py::class_<AvgPool2dImpl, Module, std::shared_ptr<AvgPool2dImpl>>(m, "AvgPool2d") .def(py::init(&make_avgpool2d), py::arg("kernel"), py::arg("stride") = std::vector<index_t>{1, 1}, py::arg("padding") = std::vector<index_t>{0, 0}) .def(py::init(&make_avgpool2d_sv), py::arg("kernel"), py::arg("stride") = index_t{1}, py::arg("padding") = index_t{0}) .def("parameters", &AvgPool2dImpl::parameters) .def("forward", &AvgPool2dImpl::forward) .def("__call__", [](AvgPool2dImpl& self, Variable& input) { return self.forward(input); }) .def("__repr__", [](const AvgPool2dImpl& v) { std::stringstream buf; buf << v; return buf.str(); }); }