You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Totally, I have two problems. Firstly,
In the mobilenet_v1_eval.py, yeah, it's eval not train. When is_training=False, you will not get a right result. When is_training=True, you can get a right answer. Obviously, it's wrong! I guess it's a big bug, but I cannot figure it out. Someone knows that?
defbuild_model():
"""Build the mobilenet_v1 model for evaluation. Returns: g: graph with rewrites after insertion of quantization ops and batch norm folding. eval_ops: eval ops for inference. variables_to_restore: List of variables to restore from checkpoint. """g=tf.Graph()
withg.as_default():
inputs, labels=flower_input(is_training=False)
scope=mobilenet_v1.mobilenet_v1_arg_scope(
is_training=True, weight_decay=0.0)
withslim.arg_scope(scope):
logits, _=mobilenet_v1.mobilenet_v1(
inputs,
is_training=True,
depth_multiplier=FLAGS.depth_multiplier,
num_classes=FLAGS.num_classes)
ifFLAGS.quantize:
tf.contrib.quantize.create_eval_graph()
eval_ops=metrics(logits, labels)
returng, eval_ops
Secondly,
I use export_eval_pbtxt() to get the "mobilenet_v1_eval.pbtxt".
Then I use the frozen .pb file to classify an image, it won't get a right result, no matter you use is_training is True or False above to get the "mobilenet_v1_eval.pbtxt".
And the classify file is:
from __future__ importabsolute_importfrom __future__ importdivisionfrom __future__ importprint_functionimportargparseimportos.pathimportreimportsysimporttarfileimportnumpyasnpfromsix.movesimporturllibimporttensorflowastfFLAGS=Nonedefcreate_graph():
"""Creates a graph from saved GraphDef file and returns a saver."""# Creates graph from saved graph_def.pb.withtf.gfile.FastGFile(os.path.join(FLAGS.model_dir, r'/home/lg/projects/frozen_mobilenet_v1_224.pb'), 'rb') asf:
graph_def=tf.GraphDef()
graph_def.ParseFromString(f.read())
_=tf.import_graph_def(graph_def,return_elements=['MobilenetV1/Predictions/Reshape_1:0'], name='lg')
defrun_inference_on_image(image):
"""Runs inference on an image. Args: image: Image file name. Returns: Nothing """ifnottf.gfile.Exists(image):
tf.logging.fatal('File does not exist %s', image)
image_data=tf.gfile.FastGFile(image, 'rb').read()
img_data_jpg=tf.image.decode_jpeg(image_data) #图像解码 img_data_jpg=tf.image.convert_image_dtype(img_data_jpg, dtype=tf.float32) #改变图像数据的类型img_data_jpg=tf.image.resize_image_with_crop_or_pad(img_data_jpg,224,224)
# Creates graph from saved GraphDef.create_graph()
withtf.Session() assess:
image_data=img_data_jpg.eval().reshape(-1,224,224,3)
softmax_tensor=sess.graph.get_tensor_by_name('lg/MobilenetV1/Predictions/Reshape_1:0')
predictions=sess.run(softmax_tensor, {'lg/Placeholder:0': image_data})
predictions=np.squeeze(predictions)
print('predictions: ',predictions)
# Read the labels from label.txt.label_path=os.path.join(FLAGS.model_dir, '/home/lg/projects/labels.txt')
label=np.loadtxt(fname=label_path,dtype=str)
top_k=predictions.argsort()[-FLAGS.num_top_predictions:][::-1]
fornode_idintop_k:
label_string=label[node_id]
score=predictions[node_id]
print('%s (score = %.5f)'% (label_string, score))
defmain(_):
image= (FLAGS.image_fileifFLAGS.image_fileelseos.path.join(FLAGS.model_dir, 'cropped_panda.jpg'))
run_inference_on_image(image)
if__name__=='__main__':
parser=argparse.ArgumentParser()
# graph_def.pb: Binary representation of the GraphDef protocol buffer.# label.txt: the labels according to data tfrecordparser.add_argument(
'--model_dir',
type=str,
default='/tmp/imagenet',
help='Path to graph_def.pb and label.txt'
)
parser.add_argument(
'--image_file',
type=str,
default=r'/home/lg/projects/data/flower_photos/daisy/5673728_71b8cb57eb.jpg',
help='Absolute path to image file.'
)
parser.add_argument(
'--num_top_predictions',
type=int,
default=2,
help='Display this many predictions.'
)
FLAGS, unparsed=parser.parse_known_args()
tf.app.run(main=main, argv=[sys.argv[0]] +unparsed)
when i run : bash ./scripts/train_mobilenet_on_imagenet.sh
i got:
WARNING:tensorflow:From eval_image_classifier.py:94: get_or_create_global_step (from tensorflow.contrib.framework.python.ops.variables) is deprecated and will be removed in a future version.
Instructions for updating:
Please switch to tf.train.get_or_create_global_step
can you give some help? did you get zhe same bug?
Totally, I have two problems.
Firstly,
In the mobilenet_v1_eval.py, yeah, it's eval not train. When is_training=False, you will not get a right result. When is_training=True, you can get a right answer. Obviously, it's wrong! I guess it's a big bug, but I cannot figure it out. Someone knows that?
Secondly,
I use export_eval_pbtxt() to get the "mobilenet_v1_eval.pbtxt".
Then, frozen the graph:
Then I use the frozen .pb file to classify an image, it won't get a right result, no matter you use is_training is True or False above to get the "mobilenet_v1_eval.pbtxt".
And the classify file is:
The mobilenet v1 I used is in https://github.com/tensorflow/models/tree/master/research/slim/nets .
I have tried inception v3, whether to eval or classify an image. So I think mobilenet_v1_eval.py must have a bug.
Anyone can help me?
Many thanks.
All the codes I used are in https://github.com/GarryLau/draft_notes/tree/master/TF .
@Zehaos @aselle @poxvoculi
The text was updated successfully, but these errors were encountered: