Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert to ios application #2

Closed
fanlovejx opened this issue May 14, 2020 · 3 comments
Closed

Convert to ios application #2

fanlovejx opened this issue May 14, 2020 · 3 comments

Comments

@fanlovejx
Copy link

Hi Alireza Keshavarzi, last week i found your amazing work, and it work like a charm, i'm trying to porting it to ios application but so far i'm stucked, can you guide me some tip,

i'm trying to convert model to PB format then to tflite, i'm stuck at define output_node_name for conver to pb step (['InceptionV4/Logits/Predictions']), then i'm using all possible node name

min_graph = tf.compat.v1.graph_util.convert_variables_to_constants(session, session.graph_def, [node.name for node in graph.as_graph_def().node])
tf.train.write_graph(min_graph, "logdir/", "file.pb", as_text=False)
with open('output_graph.pb', 'wb') as f:
f.write(min_graph.SerializeToString())

i got success output pb file, but when load it i got these error

GRAPH_PB_PATH = 'logdir/file.pb'
with tf.Session() as sess:
print("load graph")
with gfile.FastGFile(GRAPH_PB_PATH,'rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
sess.graph.as_default()
tf.import_graph_def(graph_def, name='3A4Bh-Ref25')

=> ERROR: ValueError:ValueError: Input 0 of node 3A4Bh-Ref25/global_step/Assign was passed int32 from 3A4Bh-Ref25/global_step:0 incompatible with expected int32_ref.

so i'm stucked here

Please help me,
Thanks and Besst Regard

@fanlovejx
Copy link
Author

Update: i've find out that the output node name are "InceptionV4/y:0"
now i have pb file which maybe corect

Then i got new error

TypeError: Cannot interpret feed_dict key as Tensor: The name 'flag_placeholder:0' refers to a Tensor which does not exist. The operation, 'flag_placeholder', does not exist in the graph.

When trying to invoke run with params generator from your inferno.py

@fanlovejx
Copy link
Author

Update: i'm successfull to convert to pb model type, also success make prediction, and it work like a charm :D. so i'm sharing the guide to anyone who interested like me:

  1. Convert trained model(3A4Bh-Ref25) to pb, the output node name are "InceptionV4/y:0", remove ":0" to freeze graph

  2. load the pb file with these lines:
    with gfile.FastGFile(GRAPH_PB_PATH,'rb') as f:
    graph_def = tf.GraphDef()
    graph_def.ParseFromString(f.read())
    import_graph_def(graph_def, name='')

  3. run prediction with same input as base_model.py did, for output do not use as base_model.py, use ['InceptionV4/y:0'] instead [self.logits]

@isohrab
Copy link
Owner

isohrab commented May 15, 2020

@fanlovejx , I'm happy that you could solve your problem and my repo is useful for you. I'm excited to see your results. if possible record a demo and publish to youtube or somewhere else.

@isohrab isohrab closed this as completed May 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants