Comments (17)
from ofxtensorflow2.
Sorry i don't expressed myself ok.
That feature was not on ccpflow2 but was on cppflow1, i added a pair of methods to cppflow2 and one to ofxTF2Model and now i can use a tf1 frozen graph with your addon.
So i just asking if you can consider to add that feature as it makes more "open" as you are not restricted to savedmodel format.
Its only a suggestion
from ofxtensorflow2.
from ofxtensorflow2.
exactly, in fact i see there is a pending pr to cppflow that also do that
from ofxtensorflow2.
Hey @natxopedreira,
That is in fact a very cool feature and we ll happily review and accept a PR :)
from ofxtensorflow2.
Great! Will prepare it and upload to my fork
from ofxtensorflow2.
I have a question about the preffered style to use.
I need to add a second constructor to cppflow model class to have one constructor to use with frozen and another to savedmodel so both will have the url string as parameter, right now as im in a hurry i added a dummy second parameter to the constructor of frozen and done, but i want to do it ok to send the pr.
I can for example on the "frozen" constructor send TF_Buffer as parameter instead the string with the path or a file...
Ideas on how to deal with the second constructor?
I dont know if im explaining myself ok :)
from ofxtensorflow2.
Ideas on how to deal with the second constructor?
I dont know if im explaining myself ok :)
Can you add pseudo code here via Markdown?
from ofxtensorflow2.
Sure, here is what im using, you can see the ugly hack of adding the dummy second parameter to model constructor
model.h
inline TF_Buffer *model::readGraph(const std::string& filename) {
std::ifstream file (filename, std::ios::binary | std::ios::ate);
// Error opening the file
if (!file.is_open()) {
std::cerr << "Unable to open file: " << filename << std::endl;
return nullptr;
}
// Cursor is at the end to get size
auto size = file.tellg();
// Move cursor to the beginning
file.seekg (0, std::ios::beg);
// Read
auto data = std::make_unique<char[]>(size);
file.seekg (0, std::ios::beg);
file.read (data.get(), size);
// Error reading the file
if (!file) {
std::cerr << "Unable to read the full file: " << filename << std::endl;
return nullptr;
}
// Create tensorflow buffer from read data
TF_Buffer* buffer = TF_NewBufferFromString(data.get(), size);
// Close file and remove data
file.close();
return buffer;
}
inline model::model(const std::string &filename, float p) {
this->graph = {TF_NewGraph(), TF_DeleteGraph};
auto session_deleter = [](TF_Session* sess) {
TF_DeleteSession(sess, context::get_status());
status_check(context::get_status());
};
std::unique_ptr<TF_SessionOptions, decltype(&TF_DeleteSessionOptions)> sess_opts = {TF_NewSessionOptions(), TF_DeleteSessionOptions};
this->session = {TF_NewSession(this->graph.get(), sess_opts.get(), context::get_status()),session_deleter};
status_check(context::get_status());
// Import the graph definition
TF_Buffer* def = readGraph(filename);
if(def == nullptr) {
throw std::runtime_error("Failed to import gragh def from file");
}
std::unique_ptr<TF_ImportGraphDefOptions, decltype(&TF_DeleteImportGraphDefOptions)> graph_opts = {TF_NewImportGraphDefOptions(), TF_DeleteImportGraphDefOptions};
TF_GraphImportGraphDef(this->graph.get(), def, graph_opts.get(), context::get_status());
TF_DeleteBuffer(def);
status_check(context::get_status());
}
ofxTF2Model.h
bool Model::loadGraph(const std::string & modelPath) {
Model::clear();
auto model = new cppflow::model(modelPath,0.5);
if(!model) {
modelPath_ = "";
ofLogError("ofxTensorFlow2") << "Model: model could not be initialized!";
return false;
}
model_ = model;
modelPath_ = modelPath;
ofLogVerbose("ofxTensorFlow2") << "Model: loaded model: " << modelPath_;
return true;
}
from ofxtensorflow2.
First of all thanks for your contribution!
If it's a cppflow thing than I think we need to wait for the original PR to happen. I think they did a really good job and maybe they have their reasons for not accepting it yet...
in the meantime we could create a branch that pulls from the fork where the PR comes from and merge your edits to the Model class.
from ofxtensorflow2.
super!!!! but @bytosaur that take a look at the code in pr first.
-
There is code that is not need as is taken directly from the actual constructor and not related in this case.
-
They take code from ccpflow 1 and seting the config_options for session no longer works that way, it will no crash but those will not work, i for example spend hours trying to enable gpu percentage ussage as those options suggested on cppflow1 and the silent fail... and finally find that is not need as current implementation in cppflow2 works
I will suggest make your own branch, use the code cleaned and wait if they solved/merge that one
from ofxtensorflow2.
Right, it reminded me of the code for the GPU settings which is not related to the model. I dont think it should belong there even if it works.
so, yeah it s probably best to fork cppflow and edit it on our own.
from ofxtensorflow2.
no it dont work, you dont get any error but no longer works....
from ofxtensorflow2.
hey @natxopedreira,
I have forked and modified the model class of cppflow here
I have added a branch containing changes:
the model can be downloaded here
let me know what you think :) and thanks for the support
from ofxtensorflow2.
argh! i keep getting problems with those submodules...
this solved it however
[main] $ git submodule deinit
[main] $ git checkout 'new_branch'
[new_branch] $ git submodule update --init --recursive
from ofxtensorflow2.
I like it very much! great solution with the enum!!! and i think having support for frozen graph is super cool as you can use tf1 models. I think you should add a note on readme about that
Thanks!!!
from ofxtensorflow2.
from ofxtensorflow2.
Related Issues (20)
- off topic model issue HOT 3
- "Undefined symbols for architecture arm64: "_TF_NewSessionOptions", referenced from:" on macOS ? HOT 6
- Do you have plans to implement 3d skeleton detection via BlazePose? HOT 4
- word2vec / universal sentence encoder example? HOT 8
- Error compiling: No member named 'exchange' in namespace 'std' HOT 14
- arbitrary-image-stylization-v1-256 HOT 13
- trained model different format? HOT 5
- GPU training issue HOT 1
- Training with larger image size - pix2pix HOT 2
- example_video_and_image_colorization HOT 7
- Yolo v4 example HOT 12
- Chatbot example :)
- music generation example HOT 6
- Stable diffusion or other text-to-image networks? HOT 3
- Compilation issues for M1 / arm64 HOT 3
- configure_xcode.sh script breaks Xcode projects HOT 1
- git submodule update not working on macOS HOT 12
- error: Library not loaded HOT 5
- error: Signing Identity: “-” HOT 2
- error: Library not loaded: "@rpath/libtensorflow.2.dylib' HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ofxtensorflow2.