Skip to content

Commit

Permalink
Fixup debug prints and cleanup print statement consistency in general.
Browse files Browse the repository at this point in the history
  • Loading branch information
rwightman committed Oct 5, 2016
1 parent 63c1faf commit 1d5e5d8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
17 changes: 10 additions & 7 deletions script/bag2tf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# http:https://www.apache.org/licenses/LICENSE-2.0
# ==============================================================================

from __future__ import print_function
from cv_bridge import CvBridge, CvBridgeError
import os
import sys
Expand Down Expand Up @@ -110,7 +111,6 @@ def __init__(self, outdir, name, num_entries, num_shards=256):

def _update_writer(self):
if not self._writer or self._shard_counter >= self.num_entries_per_shard:
sys.stdout.flush()
shard = self._counter // self.num_entries_per_shard
assert(shard <= self.num_shards)
output_filename = '%s-%.5d-of-%.5d' % (self.name, shard, self.num_shards)
Expand Down Expand Up @@ -150,8 +150,6 @@ def main():
separate_streams = args.separate
num_images = args.num_images # FIXME detect from bag_info (takes more time)

print type(num_images)
print separate_streams
bridge = CvBridge()

filter_topics = [LEFT_CAMERA_TOPIC, CENTER_CAMERA_TOPIC, RIGHT_CAMERA_TOPIC, STEERING_TOPIC]
Expand All @@ -168,16 +166,17 @@ def main():
shard_writer = ShardWriter(single_outdir, 'combined', 3*num_images, num_shards=128)

latest_steering_msg = None

example_count = 0
with rosbag.Bag(rosbag_file, "r") as bag:
for topic, msg, t in bag.read_messages(topics=filter_topics):
if (topic == LEFT_CAMERA_TOPIC or
topic == CENTER_CAMERA_TOPIC or
topic == RIGHT_CAMERA_TOPIC):

if debug_print:
print msg.frame_id + str(msg.header.stamp.to_nsec())
print 'steering %u : image %u' % (latest_steering_msg.header.stamp.to_nsec(), msg.header.stamp.to_nsec())
print("%s_camera %d" % (msg.header.frame_id[0], msg.header.stamp.to_nsec()))
print("steering %d, %f" %
(latest_steering_msg.header.stamp.to_nsec(), latest_steering_msg.steering_wheel_angle))

if separate_streams:
if topic == LEFT_CAMERA_TOPIC:
Expand All @@ -190,12 +189,16 @@ def main():
writer = shard_writer

write_example(writer, bridge, msg, latest_steering_msg, image_fmt=img_format)
example_count += 1

elif topic == STEERING_TOPIC:
if debug_print:
print 'steering %u : %f, %f' % (msg.header.stamp.to_nsec(), msg.steering_wheel_angle)
print("steering %d, %f" % (msg.header.stamp.to_nsec(), msg.steering_wheel_angle))

latest_steering_msg = msg

print("Completed processing %d images to TF examples." % example_count)
sys.stdout.flush()


if __name__ == '__main__':
Expand Down
9 changes: 5 additions & 4 deletions script/bagdump.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# http:https://www.apache.org/licenses/LICENSE-2.0
# ==============================================================================

from __future__ import print_function
from cv_bridge import CvBridge, CvBridgeError
from collections import defaultdict
import os
Expand Down Expand Up @@ -83,19 +84,19 @@ def main():
for topic, msg, t in bag.read_messages(topics=filter_topics):
if topic == LEFT_CAMERA_TOPIC:
if debug_print:
print 'l_camera ' + str(msg.header.stamp.to_nsec())
print("l_camera %d" % msg.header.stamp.to_nsec())
write_image(bridge, left_outdir, msg, fmt=img_format, table=camera_dict)
elif topic == CENTER_CAMERA_TOPIC:
if debug_print:
print 'c_camera ' + str(msg.header.stamp.to_nsec())
print("c_camera %d" % msg.header.stamp.to_nsec())
write_image(bridge, center_outdir, msg, fmt=img_format, table=camera_dict)
elif topic == RIGHT_CAMERA_TOPIC:
if debug_print:
print 'r_camera ' + str(msg.header.stamp.to_nsec())
print("r_camera %d" % msg.header.stamp.to_nsec())
write_image(bridge, right_outdir, msg, fmt=img_format, table=camera_dict)
elif topic == STEERING_TOPIC:
if debug_print:
print 'steering %u : %f, %f' % (msg.header.stamp.to_nsec(), msg.steering_wheel_angle)
print("steering %d %f" % (msg.header.stamp.to_nsec(), msg.steering_wheel_angle))
steering_dict["seq"].append(msg.header.seq)
steering_dict["timestamp"].append(msg.header.stamp.to_nsec())
steering_dict["angle"].append(msg.steering_wheel_angle)
Expand Down
7 changes: 4 additions & 3 deletions script/readtf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# http:https://www.apache.org/licenses/LICENSE-2.0
# ==============================================================================

from __future__ import print_function
import os
import sys
import tensorflow as tf
Expand Down Expand Up @@ -90,15 +91,15 @@ def main():
assert decoded_image.shape[2] == 3
read_count += len(read_output)
if not read_count % 1000:
print "Read %d examples" % read_count
print("Read %d examples" % read_count)

except tf.errors.OutOfRangeError:
print "Reading stopped by Queue"
print("Reading stopped by Queue")
finally:
# Ask the threads to stop.
coord.request_stop()

print 'Done reading %d images' % read_count
print("Done reading %d images" % read_count)

# Wait for threads to finish.
coord.join(threads)
Expand Down

0 comments on commit 1d5e5d8

Please sign in to comment.