Commit 668bda46 authored by Dan Wilcox's avatar Dan Wilcox
Browse files

Merge branch 'develop' into update/macos-arm64

parents 44594f24 d6246275
1.3.0: 2022?
* added version as download_tensorflow script first argument
* add details about movenet model input batch size and recommended dimensions
* updated to libtensorflow 2.7.0
* cleaned up example_video_matting
* example_movenet doesnt need ofxCv
1.2.2: 2021 Sep 22
* added example_video_matting (Natxopedreira)
......
......@@ -122,6 +122,12 @@ When opting for GPU support set the `TYPE` script variable:
TYPE=gpu ./scripts/download_tensorflow.sh
```
Additionally, to use a specific version supply it as the first argument:
```shell
./scripts/download_tensorflow.sh 2.7.0
```
See <https://www.tensorflow.org/install/gpu> for more information on GPU support for TensorFlow.
### Ubuntu / Linux
......
......@@ -8,12 +8,11 @@
#include "ofApp.h"
//========================================================================
int main( ){
ofGLWindowSettings settings;
settings.setGLVersion(3, 2); // try also 2, 1
settings.setSize(1920, 1080);
settings.windowMode = OF_WINDOW;
ofCreateWindow(settings);
ofRunApp( new ofApp());
int main() {
ofGLWindowSettings settings;
settings.setGLVersion(3, 2); // try also 2, 1
settings.setSize(1280, 720);
settings.windowMode = OF_WINDOW;
ofCreateWindow(settings);
ofRunApp(new ofApp());
}
......@@ -43,65 +43,69 @@ void ofApp::setup() {
};
model.setup(inputNames, outputNames);
auto r1i = cppflow::tensor({0.0f});
auto r2i = cppflow::tensor({0.0f});
auto r3i = cppflow::tensor({0.0f});
auto r4i = cppflow::tensor({0.0f});
auto src = cppflow::tensor({1.0f, nnHeight, nnWidth, 3.0f});
auto downsample_ratio = cppflow::tensor({0.25f});
vectorOfInputTensors.push_back(downsample_ratio);
vectorOfInputTensors.push_back(r1i);
vectorOfInputTensors.push_back(r2i);
vectorOfInputTensors.push_back(r3i);
vectorOfInputTensors.push_back(r4i);
vectorOfInputTensors.push_back(src);
mask.allocate(video.getWidth(), video.getHeight(), OF_IMAGE_GRAYSCALE);
outputMasked.allocate(video.getWidth(), video.getHeight(), OF_IMAGE_COLOR_ALPHA);
outputMasked.getTexture().setAlphaMask(mask.getTexture());
// model-specific inputs
inputs = {
cppflow::tensor({0.25f}), // downsample ratio
cppflow::tensor({0.0f}), // r1i
cppflow::tensor({0.0f}), // r2i
cppflow::tensor({0.0f}), // r3i
cppflow::tensor({0.0f}), // r4i
cppflow::tensor({1.0f, nnHeight, nnWidth, 3.0f}) // src
};
imgMask.allocate(video.getWidth(), video.getHeight(), OF_IMAGE_GRAYSCALE);
imgOut.allocate(video.getWidth(), video.getHeight(), OF_IMAGE_COLOR_ALPHA);
imgOut.getTexture().setAlphaMask(imgMask.getTexture());
imgBackground.load("bg.jpg");
}
//--------------------------------------------------------------
void ofApp::update() {
video.update();
video.update();
if(video.isFrameNew()) {
ofPixels & pixels = video.getPixels();
auto inputpxs = ofxTF2::pixelsToTensor(pixels);
auto inputCast = cppflow::cast(inputpxs, TF_UINT8, TF_FLOAT);
// prepare inputs
auto input = ofxTF2::pixelsToTensor(pixels);
auto inputCast = cppflow::cast(input, TF_UINT8, TF_FLOAT);
inputCast = cppflow::mul(inputCast, cppflow::tensor({1/255.0f}));
inputCast = cppflow::expand_dims(inputCast, 0);
inputs[5] = inputCast;
vectorOfInputTensors[5] = inputCast;
auto vectorOfOutputTensors = model.runMultiModel(vectorOfInputTensors);
vectorOfInputTensors[1] = vectorOfOutputTensors[2];
vectorOfInputTensors[2] = vectorOfOutputTensors[3];
vectorOfInputTensors[3] = vectorOfOutputTensors[4];
vectorOfInputTensors[4] = vectorOfOutputTensors[5];
// run model
auto outputs = model.runMultiModel(inputs);
auto foreground = vectorOfOutputTensors[1];
// process outputs
inputs[1] = outputs[2];
inputs[2] = outputs[3];
inputs[3] = outputs[4];
inputs[4] = outputs[5];
auto foreground = outputs[1];
foreground = cppflow::mul(foreground, cppflow::tensor({255.0f}));
auto foregroundMod = cppflow::cast(foreground, TF_FLOAT, TF_UINT8);
ofxTF2::tensorToImage(foreground, mask);
mask.update();
outputMasked.setFromPixels(video.getPixels());
ofxTF2::tensorToImage(foreground, imgMask);
imgMask.update();
imgOut.setFromPixels(video.getPixels());
}
}
//--------------------------------------------------------------
void ofApp::draw() {
float w = ofGetWidth() / 2;
float h = ofGetHeight() / 2;
// row 1
video.draw(0, 0, w, h);
imgMask.draw(w, 0, w, h);
video.draw(0, 0, video.getWidth()/2, video.getHeight()/2);
mask.draw( video.getWidth()/2,0, video.getWidth()/2, video.getHeight()/2);
// row 2
imgBackground.draw(w/2, h, w, h);
imgOut.draw(w/2, h, w, h);
bg.draw(0,video.getHeight()/2, video.getWidth()/2, video.getHeight()/2);
outputMasked.draw(0,video.getHeight()/2, video.getWidth()/2, video.getHeight()/2);
ofDrawBitmapStringHighlight(ofToString((int)ofGetFrameRate()) + " fps", 4, 12);
}
//--------------------------------------------------------------
......
......@@ -47,9 +47,9 @@ class ofApp : public ofBaseApp {
// model
ofxTF2::Model model;
ofImage bg;
ofImage mask;
ofImage outputMasked;
std::vector<cppflow::tensor> inputs;
std::vector<cppflow::tensor> vectorOfInputTensors;
ofImage imgMask;
ofImage imgBackground;
ofImage imgOut;
};
......@@ -11,8 +11,11 @@
# stop on error
set -e
# tf version
VER=2.6.0
# tf version: optional argument
VER=2.7.0
if [ "$1" != "" ] ; then
VER=$1
fi
# tf type: cpu or gpu,
# override when running via: TYPE=gpu ./download_tensorflow.sh
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment