Skip to content

Commit

Permalink
Cleaned up TODO's and added filesystem
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrhm committed Jan 20, 2024
1 parent 84a9b69 commit 656f357
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 35 deletions.
7 changes: 3 additions & 4 deletions src/perception/object_detector/inference.cu
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ namespace mrover {
constexpr static char const* INPUT_BINDING_NAME = "images";
constexpr static char const* OUTPUT_BINDING_NAME = "output0";

Inference::Inference(std::string const& onnxModelPath, cv::Size modelInputShape = {640, 640}, std::string const& classesTxtFile = "") {
Inference::Inference(std::filesystem::path const& onnxModelPath) {
//Create the engine object from either the file or from onnx file
mEngine = std::unique_ptr<ICudaEngine, Destroy<ICudaEngine>>{createCudaEngine(onnxModelPath)};
if (!mEngine) throw std::runtime_error("Failed to create CUDA engine");

//Log the Engine was created
mLogger.log(ILogger::Severity::kINFO, "Created CUDA Engine");

//Check some assumptions about the model
Expand All @@ -44,8 +43,8 @@ namespace mrover {
prepTensors();
}

ICudaEngine* Inference::createCudaEngine(std::string const& onnxModelPath) {
// See link sfor additional context
ICudaEngine* Inference::createCudaEngine(std::filesystem::path const& onnxModelPath) {
//Define the size of Batches
constexpr auto explicitBatch = 1U << static_cast<uint32_t>(NetworkDefinitionCreationFlag::kEXPLICIT_BATCH);

//Init logger
Expand Down
7 changes: 2 additions & 5 deletions src/perception/object_detector/inference.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ namespace mrover {
//Bindings
std::array<void*, 2> mBindings{};

//ONNX Model Path
std::string mOnnxModelPath{};

//Size of Model
cv::Size mModelInputShape;
cv::Size mModelOutputShape;
Expand All @@ -41,7 +38,7 @@ namespace mrover {

private:
//Creates a ptr to the engine
ICudaEngine* createCudaEngine(std::string const& onnxModelPath);
ICudaEngine* createCudaEngine(std::filesystem::path const& onnxModelPath);

//Launch the model execution onto the GPU
void launchInference(cv::Mat const& input, cv::Mat const& output) const;
Expand All @@ -54,7 +51,7 @@ namespace mrover {

public:
//Inference Constructor
Inference(std::string const& onnxModelPath, cv::Size modelInputShape, std::string const& classesTxtFile);
Inference(std::filesystem::path const& onnxModelPath);

//Forward Pass of the model
void doDetections(const cv::Mat& img) const;
Expand Down
4 changes: 2 additions & 2 deletions src/perception/object_detector/inference_wrapper.cu
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ using namespace nvinfer1;
*/
namespace mrover {

InferenceWrapper::InferenceWrapper(std::string onnxModelPath, cv::Size const modelInputShape = {640, 640}, std::string classesTxtFile = "") : mInference({}) {
InferenceWrapper::InferenceWrapper(std::string onnxModelPath) : mInference({}) {
//Initialize the unique_ptr to the inference class
mInference.reset(new Inference(std::move(onnxModelPath), modelInputShape, std::move(classesTxtFile)));
mInference.reset(new Inference(std::move(onnxModelPath)));
}


Expand Down
2 changes: 1 addition & 1 deletion src/perception/object_detector/inference_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace mrover {
~InferenceWrapper() = default;

//Inference Wrapper Constructor
InferenceWrapper(std::string onnxModelPath, cv::Size const modelInputShape, std::string classesTxtFile);
InferenceWrapper(std::string onnxModelPath);

//Forward Pass on the model
void doDetections(cv::Mat const& img) const;
Expand Down
7 changes: 1 addition & 6 deletions src/perception/object_detector/object_detector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,13 @@ namespace mrover {
std::filesystem::path packagePath = ros::package::getPath("mrover");
std::filesystem::path modelPath = packagePath / "data" / "best.onnx";

// TODO: resolution should be a parameter
// TODO: get size of the model from the model itself
// TODO: remove empty string
mInferenceWrapper = InferenceWrapper{modelPath, cv::Size{640, 640}, ""};
mInferenceWrapper = InferenceWrapper{modelPath};

//Create the publishers and subscribers for the detected image and the debug image
mImgSub = mNh.subscribe("/camera/left/points", 1, &ObjectDetectorNodelet::imageCallback, this);
mDebugImgPub = mNh.advertise<sensor_msgs::Image>("/object_detector/debug_img", 1);
mDetectionData = mNh.advertise<DetectedObject>("/object_detector/detected_object", 1);

//READ ROS PARAMETERS

//Create the Reference Frames
mNh.param<std::string>("camera_frame", mCameraFrameId, "zed2i_left_camera_frame");
mNh.param<std::string>("world_frame", mMapFrameId, "map");
Expand Down
5 changes: 0 additions & 5 deletions src/perception/object_detector/object_detector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ namespace mrover {
//Mat for the image from the point cloud
cv::Mat mImg;

//Image information
constexpr static int NUM_CHANNELS = 3;
constexpr static int IMG_WIDTH = 1280;
constexpr static int IMG_HEIGHT = 720;

//List of class names
std::vector<std::string> classes{"Hammer"};//{"person", "bicycle", "car", "motorcycle", "airplane", "bus", "train", "truck", "boat", "traffic light", "fire hydrant", "stop sign", "parking meter", "bench", "bird", "cat", "dog", "horse", "sheep", "cow", "elephant", "bear", "zebra", "giraffe", "backpack", "umbrella", "handbag", "tie", "suitcase", "frisbee", "skis", "snowboard", "sports ball", "kite", "baseball bat", "baseball glove", "skateboard", "surfboard", "tennis racket", "bottle", "wine glass", "cup", "fork", "knife", "spoon", "bowl", "banana", "apple", "sandwich", "orange", "broccoli", "carrot", "hot dog", "pizza", "donut", "cake", "chair", "couch", "potted plant", "bed", "dining table", "toilet", "tv", "laptop", "mouse", "remote", "keyboard", "cell phone", "microwave", "oven", "toaster", "sink", "refrigerator", "book", "clock", "vase", "scissors", "teddy bear", "hair drier", "toothbrush"};

Expand Down
13 changes: 1 addition & 12 deletions src/perception/object_detector/pch.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <algorithm>//TODO: clean up :)
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
Expand All @@ -17,17 +17,6 @@
#include <string>
#include <type_traits>
#include <unordered_map>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <execution>
#include <limits>
#include <numeric>
#include <optional>
#include <string>
#include <type_traits>
#include <unordered_map>


#include <boost_cpp23_workaround.hpp>

Expand Down

0 comments on commit 656f357

Please sign in to comment.