Skip to content

Commit

Permalink
Fix issue when setting memory growth
Browse files Browse the repository at this point in the history
When calling tf.config.experimental.set_memory_growth, we want to set the value to True for all physical devices.
Otherwise the following ValueError is produce: 'Memory growth cannot differ between GPU devices'
  • Loading branch information
marcelvanworkum committed Apr 5, 2020
1 parent 65294d5 commit 67d666f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

def main(_argv):
physical_devices = tf.config.experimental.list_physical_devices('GPU')
if len(physical_devices) > 0:
tf.config.experimental.set_memory_growth(physical_devices[0], True)
for physical_device in physical_devices:
tf.config.experimental.set_memory_growth(physical_device, True)

if FLAGS.tiny:
yolo = YoloV3Tiny(classes=FLAGS.num_classes)
Expand Down
6 changes: 3 additions & 3 deletions detect_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

def main(_argv):
physical_devices = tf.config.experimental.list_physical_devices('GPU')
if len(physical_devices) > 0:
tf.config.experimental.set_memory_growth(physical_devices[0], True)
for physical_device in physical_devices:
tf.config.experimental.set_memory_growth(physical_device, True)

if FLAGS.tiny:
yolo = YoloV3Tiny(classes=FLAGS.num_classes)
Expand Down Expand Up @@ -63,7 +63,7 @@ def main(_argv):
time.sleep(0.1)
continue

img_in = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img_in = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img_in = tf.expand_dims(img_in, 0)
img_in = transform_images(img_in, FLAGS.size)

Expand Down
4 changes: 2 additions & 2 deletions train.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@

def main(_argv):
physical_devices = tf.config.experimental.list_physical_devices('GPU')
if len(physical_devices) > 0:
tf.config.experimental.set_memory_growth(physical_devices[0], True)
for physical_device in physical_devices:
tf.config.experimental.set_memory_growth(physical_device, True)

if FLAGS.tiny:
model = YoloV3Tiny(FLAGS.size, training=True,
Expand Down

0 comments on commit 67d666f

Please sign in to comment.