Commit 8cf8446b authored by Yukun Zhu's avatar Yukun Zhu Committed by aquariusjay
Browse files

Adding panoptic evaluation tools and update internal changes. (#6320)

* Internal changes

PiperOrigin-RevId: 237183552

* update readme

PiperOrigin-RevId: 237184584
parent 05a79f5a
...@@ -129,10 +129,10 @@ def main(unused_argv): ...@@ -129,10 +129,10 @@ def main(unused_argv):
model_options=model_options, model_options=model_options,
eval_scales=FLAGS.inference_scales, eval_scales=FLAGS.inference_scales,
add_flipped_images=FLAGS.add_flipped_images) add_flipped_images=FLAGS.add_flipped_images)
raw_predictions = tf.identity(
predictions = tf.cast(predictions[common.OUTPUT_TYPE], tf.float32) tf.cast(predictions[common.OUTPUT_TYPE], tf.float32),
_RAW_OUTPUT_NAME)
# Crop the valid regions from the predictions. # Crop the valid regions from the predictions.
raw_predictions = tf.identity(predictions, _RAW_OUTPUT_NAME)
semantic_predictions = tf.slice( semantic_predictions = tf.slice(
raw_predictions, raw_predictions,
[0, 0, 0], [0, 0, 0],
......
...@@ -26,8 +26,9 @@ The remaining libraries can be installed on Ubuntu 14.04 using via apt-get: ...@@ -26,8 +26,9 @@ The remaining libraries can be installed on Ubuntu 14.04 using via apt-get:
```bash ```bash
sudo apt-get install python-pil python-numpy sudo apt-get install python-pil python-numpy
sudo pip install jupyter pip install --user jupyter
sudo pip install matplotlib pip install --user matplotlib
pip install --user PrettyTable
``` ```
## Add Libraries to PYTHONPATH ## Add Libraries to PYTHONPATH
...@@ -38,7 +39,13 @@ tensorflow/models/research/: ...@@ -38,7 +39,13 @@ tensorflow/models/research/:
```bash ```bash
# From tensorflow/models/research/ # From tensorflow/models/research/
export PYTHONPATH=$PYTHONPATH:`pwd` export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
# [Optional] for panoptic evaluation, you might need panopticapi:
# https://github.com/cocodataset/panopticapi
# Please clone it to a local directory ${PANOPTICAPI_DIR}
touch ${PANOPTICAPI_DIR}/panopticapi/__init__.py
export PYTHONPATH=$PYTHONPATH:${PANOPTICAPI_DIR}/panopticapi
``` ```
Note: This command needs to run from every new terminal you start. If you wish Note: This command needs to run from every new terminal you start. If you wish
......
...@@ -485,6 +485,7 @@ def main(unused_argv): ...@@ -485,6 +485,7 @@ def main(unused_argv):
config=session_config, config=session_config,
scaffold=scaffold, scaffold=scaffold,
checkpoint_dir=FLAGS.train_logdir, checkpoint_dir=FLAGS.train_logdir,
summary_dir=FLAGS.train_logdir,
log_step_count_steps=FLAGS.log_steps, log_step_count_steps=FLAGS.log_steps,
save_summaries_steps=FLAGS.save_summaries_secs, save_summaries_steps=FLAGS.save_summaries_secs,
save_checkpoint_secs=FLAGS.save_interval_secs, save_checkpoint_secs=FLAGS.save_interval_secs,
......
#!/usr/bin/python #!/usr/bin/python
# Copyright 2018 The TensorFlow Authors. All Rights Reserved. # Copyright 2018 The TensorFlow Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
# You may obtain a copy of the License at # You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, # distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# ============================================================================== # ==============================================================================
import tensorflow as tf import tensorflow as tf
import csv import csv
import os import os
import argparse import argparse
""" """
usage: usage:
Processes all .jpg, .png, .bmp and .gif files found in the specified directory and its subdirectories. Processes all .jpg, .png, .bmp and .gif files found in the specified directory and its subdirectories.
--PATH ( Path to directory of images or path to directory with subdirectory of images). e.g Path/To/Directory/ --PATH ( Path to directory of images or path to directory with subdirectory of images). e.g Path/To/Directory/
--Model_PATH path to the tensorflow model --Model_PATH path to the tensorflow model
""" """
parser = argparse.ArgumentParser(description='Crystal Detection Program') parser = argparse.ArgumentParser(description='Crystal Detection Program')
parser.add_argument('--PATH', type=str, help='path to image directory. Recursively finds all image files in directory and sub directories') # path to image directory or containing sub directories. parser.add_argument('--PATH', type=str, help='path to image directory. Recursively finds all image files in directory and sub directories') # path to image directory or containing sub directories.
parser.add_argument('--MODEL_PATH', type=str, default='./savedmodel',help='the file path to the tensorflow model ') parser.add_argument('--MODEL_PATH', type=str, default='./savedmodel',help='the file path to the tensorflow model ')
args = vars(parser.parse_args()) args = vars(parser.parse_args())
PATH = args['PATH'] PATH = args['PATH']
model_path = args['MODEL_PATH'] model_path = args['MODEL_PATH']
crystal_images = [os.path.join(dp, f) for dp, dn, filenames in os.walk(PATH) for f in filenames if os.path.splitext(f)[1] in ['.jpg','png','bmp','gif']] crystal_images = [os.path.join(dp, f) for dp, dn, filenames in os.walk(PATH) for f in filenames if os.path.splitext(f)[1] in ['.jpg','png','bmp','gif']]
size = len(crystal_images) size = len(crystal_images)
def load_images(file_list): def load_images(file_list):
for i in file_list: for i in file_list:
files = open(i,'rb') files = open(i,'rb')
yield {"image_bytes":[files.read()]},i yield {"image_bytes":[files.read()]},i
iterator = load_images(crystal_images) iterator = load_images(crystal_images)
with open(PATH +'results.csv', 'w') as csvfile: with open(PATH +'results.csv', 'w') as csvfile:
Writer = csv.writer(csvfile, delimiter=' ',quotechar=' ', quoting=csv.QUOTE_MINIMAL) Writer = csv.writer(csvfile, delimiter=' ',quotechar=' ', quoting=csv.QUOTE_MINIMAL)
predicter= tf.contrib.predictor.from_saved_model(model_path) predicter= tf.contrib.predictor.from_saved_model(model_path)
dic = {} dic = {}
k = 0 k = 0
for _ in range(size): for _ in range(size):
data,name = next(iterator) data,name = next(iterator)
results = predicter(data) results = predicter(data)
vals =results['scores'][0] vals =results['scores'][0]
classes = results['classes'][0] classes = results['classes'][0]
dictionary = dict(zip(classes,vals)) dictionary = dict(zip(classes,vals))
print('Image path: '+ name+' Crystal: '+str(dictionary[b'Crystals'])+' Other: '+ str(dictionary[b'Other'])+' Precipitate: '+ str(dictionary[b'Precipitate'])+' Clear: '+ str(dictionary[b'Clear'])) print('Image path: '+ name+' Crystal: '+str(dictionary[b'Crystals'])+' Other: '+ str(dictionary[b'Other'])+' Precipitate: '+ str(dictionary[b'Precipitate'])+' Clear: '+ str(dictionary[b'Clear']))
Writer.writerow(['Image path: '+ name,'Crystal: '+str(dictionary[b'Crystals']),'Other: '+ str(dictionary[b'Other']),'Precipitate: '+ str(dictionary[b'Precipitate']),'Clear: '+ str(dictionary[b'Clear'])]) Writer.writerow(['Image path: '+ name,'Crystal: '+str(dictionary[b'Crystals']),'Other: '+ str(dictionary[b'Other']),'Precipitate: '+ str(dictionary[b'Precipitate']),'Clear: '+ str(dictionary[b'Clear'])])
Markdown is supported
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