Skip to content

Commit

Permalink
OpenVINO: updated grasp detector to use base Classifier
Browse files Browse the repository at this point in the history
This patch updated the "GraspDetector" to use the base Classifier.
The base Classifier was created as a shared pointer, which will be
released by system. Thus no need to explitly release "classifier_"
in the destructor "~GraspDetector()".

The base Classifer will create the right classifier (Caffe or OpenVINO)
based on build option.

The Caffe Classifer is modified to be derived from the base Classifer.

Signed-off-by: Sharron LIU <[email protected]>
  • Loading branch information
Sharron LIU committed Sep 6, 2018
1 parent 4becf29 commit 002c229
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 19 deletions.
6 changes: 3 additions & 3 deletions include/gpd/caffe_classifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#ifndef CAFFE_CLASSIFIER_H_
#define CAFFE_CLASSIFIER_H_


// System
#include <string>
#include <vector>
Expand All @@ -46,6 +45,7 @@
// OpenCV
#include <opencv2/core/core.hpp>

#include "gpd/classifier.h"

/** CaffeClassifier class
*
Expand All @@ -54,7 +54,7 @@
* This class classifies grasps as viable or not using a convolutional neural network (CNN) in the Caffe framework.
*
*/
class CaffeClassifier
class CaffeClassifier : public Classifier
{
public:

Expand All @@ -63,7 +63,7 @@ class CaffeClassifier
* \param model_file the location of the file that describes the network model
* \param weights_file the location of the file that contains the network weights
*/
CaffeClassifier(const std::string& model_file, const std::string& weights_file, bool use_gpu = true);
CaffeClassifier(const std::string& model_file, const std::string& weights_file, Classifier::Device device);

/**
* \brief Classify grasp candidates as viable grasps or not.
Expand Down
10 changes: 2 additions & 8 deletions include/gpd/grasp_detector.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@
#include <algorithm>
#include <vector>

// Caffe
#include "caffe/caffe.hpp"
#include "caffe/layers/memory_data_layer.hpp"
#include "caffe/util/io.hpp"

// PCL
#include <pcl/common/common.h>
#include <pcl/filters/statistical_outlier_removal.h>
Expand All @@ -60,7 +55,7 @@
#include <gpg/plot.h>

// Custom
#include "../gpd/caffe_classifier.h"
#include "gpd/classifier.h"
#include "../gpd/clustering.h"
#include "../gpd/learning.h"

Expand Down Expand Up @@ -91,7 +86,6 @@ class GraspDetector
delete candidates_generator_;
delete learning_;
delete clustering_;
delete classifier_;
}

/**
Expand Down Expand Up @@ -184,7 +178,7 @@ class GraspDetector
CandidatesGenerator* candidates_generator_; ///< pointer to object for grasp candidate generation
Learning* learning_; ///< pointer to object for grasp image creation
Clustering* clustering_; ///< pointer to object for clustering geometrically aligned grasps
CaffeClassifier* classifier_; ///< pointer to object for classification of candidates
std::shared_ptr<Classifier> classifier_; ///< pointer to object for classification of candidates

Learning::ImageParameters image_params_; // grasp image parameters

Expand Down
10 changes: 5 additions & 5 deletions src/gpd/caffe_classifier.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#include "../../include/gpd/caffe_classifier.h"


CaffeClassifier::CaffeClassifier(const std::string& model_file, const std::string& weights_file, bool use_gpu)
CaffeClassifier::CaffeClassifier(const std::string& model_file, const std::string& weights_file, Classifier::Device device)
{
// Initialize Caffe.
if (use_gpu)
switch (device)
{
case Classifier::Device::eGPU:
caffe::Caffe::set_mode(caffe::Caffe::GPU);
}
else
{
break;
default:
caffe::Caffe::set_mode(caffe::Caffe::CPU);
}

Expand Down
6 changes: 3 additions & 3 deletions src/gpd/grasp_detector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ GraspDetector::GraspDetector(ros::NodeHandle& node)

// Read classification parameters and create classifier.
std::string model_file, weights_file;
bool use_gpu;
int device;
node.param("model_file", model_file, std::string(""));
node.param("trained_file", weights_file, std::string(""));
node.param("min_score_diff", min_score_diff_, 500.0);
node.param("create_image_batches", create_image_batches_, true);
node.param("use_gpu", use_gpu, true);
classifier_ = new CaffeClassifier(model_file, weights_file, use_gpu);
node.param("device", device, 0);
classifier_ = Classifier::create(model_file, weights_file, static_cast<Classifier::Device>(device));

// Read grasp image parameters.
node.param("image_outer_diameter", image_params_.outer_diameter_, hand_search_params.hand_outer_diameter_);
Expand Down

0 comments on commit 002c229

Please sign in to comment.