Skip to content

Commit

Permalink
fix some bugs when loading tensorflow models
Browse files Browse the repository at this point in the history
  • Loading branch information
jveitchmichaelis committed Sep 6, 2019
1 parent 1e6cd74 commit 2506147
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 15 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ before_install:
script:
- qmake -makefile -o Makefile DeepLabel.pro
- make -j4
- bash deploy_mac.sh ./release

deploy:
provider: releases
Expand All @@ -23,7 +24,7 @@ deploy:
DWV05TXNXzHLItL4uv1XMjDJtTHosZKt9dSvqX6p1AT2tQfUinfNJDV/A4u6zjYS/vyGqoQDPNF3FpYOU3tlkbeaLSNEFc0XP4XBEqa5f1e6VPO0fsr3Hw2Vz9ezDieLXctoM2elRwKXdaL+rWg/nXMcbbOwxXGjgOWEhNzvq+xug/NjsGL6GBTEfjdDk
33oET8gTgnip3A9SeW6cc5aCmzFFqvvzvpR5hXwH4YPuvQ5lt7CY98oPMFKocESeFDwQtsmWD3ZbWu1BIRoiedffV3ghquTlVy9iADGze4mc9S9AfA5ikt1z1gfjZbbKjoGzb4nEIOjbDz1Sl79QMT40uoNXScqc9P8G5+tj0AHxCPO7+5eYDjHoo5is+
KabmLGyLuJTjUZ9nFHVO5rA6oooEpIL9Ozj6a/tMR5PcYb0X3E51WkMMOxFcWqtqQ32s67Sug3CntNns2srM+lf3dfZm8kg+8CvSSjKpOMLPvqvxeAuVnHgel7XqAzFi3of+miQPaV+AuQi2nVfXkWKX63JoWU="
file: "/Users/travis/build/jveitchmichaelis/deeplabel/deeplabel.dmg"
file: "/Users/travis/build/jveitchmichaelis/deeplabel/release/deeplabel.dmg"
skip_cleanup: true
on:
tags: true
tags: true
10 changes: 7 additions & 3 deletions src/detection/detectoropencv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,8 @@ void DetectorOpenCV::postProcessTensorflow(cv::Mat& frame, const std::vector<cv:
auto detections = outputs.at(0);
const int numDetections = detections.size[2];

/*
std::cout << "Outputs_size: " << detections.total() << std::endl;
std::cout << "Number of detections: " << numDetections << std::endl;
*/

// batch id, class id, confidence, bbox (x4)
detections = detections.reshape(1, detections.total() / 7);
Expand Down Expand Up @@ -236,6 +234,12 @@ std::vector<BoundingBox> DetectorOpenCV::infer(cv::Mat image){

std::vector<BoundingBox> detections;


// Assume we have an alpha image if 4 channels
if(image.channels() == 4){
cv::cvtColor(image, image, cv::COLOR_BGRA2BGR);
}

if(convert_depth && image.elemSize() == 2){
double minval, maxval;
cv::minMaxIdx(image, &minval, &maxval);
Expand All @@ -256,7 +260,7 @@ std::vector<BoundingBox> DetectorOpenCV::infer(cv::Mat image){
if(image.channels() != input_channels){
std::cout << "Input channel mismatch. Expecting "
<< input_channels
<< " but image has " << image.channels()
<< " channels but image has " << image.channels()
<< " channels.";

return detections;
Expand Down
2 changes: 1 addition & 1 deletion src/detection/detectoropencv.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include<vector>

#include<opencv2/opencv.hpp>
#include <opencv2/core/ocl.hpp>
#include<opencv2/core/ocl.hpp>
#include<opencv2/dnn.hpp>

#include<boundingbox.h>
Expand Down
6 changes: 5 additions & 1 deletion src/detection/detectorsetupdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@ DetectorSetupDialog::DetectorSetupDialog(QWidget *parent) :

image_width = settings->value("model_width", 0).toInt();
image_height = settings->value("model_height", 0).toInt();
image_channels = settings->value("model_channels", 0).toInt();
image_channels = settings->value("model_channels", 3).toInt();

framework = static_cast<model_framework>(settings->value("model_framework", 0).toInt());
if(framework == FRAMEWORK_DARKNET){
ui->frameworkComboBox->setCurrentText("Darknet (YOLO)");
ui->imageHeightLabel->show();
ui->imageWidthLabel->show();
}else if(framework == FRAMEWORK_TENSORFLOW){
ui->frameworkComboBox->setCurrentText("Tensorflow");
ui->imageHeightLabel->hide();
ui->imageWidthLabel->hide();
}

target = settings->value("model_target", cv::dnn::DNN_TARGET_CPU).toInt();
Expand Down
12 changes: 6 additions & 6 deletions src/detection/detectorsetupdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ private slots:
QString cfg_file;
QString weight_file;
QString names_file;
int image_width;
int image_height;
int image_channels;
int target;
bool convert_grayscale;
bool convert_depth;
int image_width = 320;
int image_height = 240;
int image_channels = 3; // default
int target = 0;
bool convert_grayscale = true;
bool convert_depth = true;
model_framework framework = FRAMEWORK_TENSORFLOW;
QString openFile(QString title, QString search_path="", QString filter="");
};
Expand Down
13 changes: 11 additions & 2 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,12 @@ void MainWindow::detectProject(void){
break;

auto image = cv::imread(image_path.toStdString(), cv::IMREAD_UNCHANGED|cv::IMREAD_ANYDEPTH);

// Assume we have an alpha image if 4 channels
if(image.channels() == 4){
cv::cvtColor(image, image, cv::COLOR_BGRA2BGR);
}

detectObjects(image, image_path);

progress.setValue(i++);
Expand Down Expand Up @@ -502,7 +508,10 @@ QRect MainWindow::refineBoundingBoxSimple(cv::Mat image, QRect bbox, int margin,
cv::Mat roi_thresh;

// Convert colour images to grayscale for thresholding
if(roi.channels() == 3){
if(roi.channels() == 4){
cv::cvtColor(roi, roi, cv::COLOR_BGRA2GRAY);
}
else if(roi.channels() == 3){
cv::cvtColor(roi, roi, cv::COLOR_BGR2GRAY);
}

Expand Down Expand Up @@ -814,7 +823,7 @@ void MainWindow::addImages(void){
QString openDir = settings->value("data_folder", QDir::homePath()).toString();
QStringList image_filenames = QFileDialog::getOpenFileNames(this, tr("Select image(s)"),
openDir,
tr("JPEG (*.jpg, *.jpeg, *.JPG, *.JPEG);;PNG (*.png, *.PNG);;BMP (*.bmp, *.BMP);;TIFF (*.tif, *.tiff, *.TIF, *.TIFF);;All images (*.jpg, *.jpeg, *.png, *.bmp, *.tiff)"));
tr("JPEG (*.jpg *.jpeg *.JPG *.JPEG);;PNG (*.png *.PNG);;BMP (*.bmp *.BMP);;TIFF (*.tif *.tiff *.TIF *.TIFF);;All images (*.jpg *.jpeg *.png *.bmp *.tiff)"));

if(image_filenames.size() != 0){
QString path;
Expand Down

0 comments on commit 2506147

Please sign in to comment.