Merged all support functions into read_graph; returning atoms#4
Conversation
|
I love the return types. Great job! Note though that you are returning a charlist (single-quoted) in the error message while a string/binary (double-quoted) would be preferred: iex(2)> graph2 = Tensorflex.read_graph("Makefile")
{:error, "Unable to import graph"} |
| if (TF_GetCode(status) != TF_OK) { | ||
| fprintf(stderr, "ERROR: Unable to import graph %s", TF_Message(status)); | ||
| return 1; | ||
| return enif_make_tuple2(env,enif_make_atom(env,"error"),enif_make_string(env, "Unable to import graph", ERL_NIF_LATIN1)); |
There was a problem hiding this comment.
Just to clarify, an Erlang string is not the same as an Elixir string. So we need to use the binary API here.
Also, note that we can return a better error, so let's do that. Here are all of the possible error values from Tensorflow. The idea is to convert each of them into an atom. So if we get TF_NOT_FOUND, we should return {:error, :not_found}. This will probably be very common, so we can encapsulate it in a C procedure.
There was a problem hiding this comment.
Noted. I completely agree-- I didn't realize I was returning char lists. Now I've shifted to enif_make_binary() wherever required. Also added this and the TF error codes to the latest PR.
@josevalim as discussed in #3 , merged all graph reading capabilities into the
read_graphfunction. This function returns aTF_Graphon successful loading of graph and an{:error,"Unable to load graph"}tuple on an unsuccessful attempt.Example is as follows (
classify_image_graph_def.pbis from Google's Imagenet model):I have an idea for the "story" around the graph loading we had talked about, so I'll be merging this PR as already discussed and adding the details of that in the next PR for your review.