Skip to content

Commit

Permalink
Allow s3fd to run at less than optimal vram availability
Browse files Browse the repository at this point in the history
  • Loading branch information
torzdf committed Mar 9, 2019
1 parent d8843ab commit 86947ec
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions plugins/extract/detect/s3fd.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def __init__(self, **kwargs):
self.name = "s3fd"
self.target = (640, 640) # Uses approx 4 GB of VRAM
self.vram = 4096
self.min_vram = 1024 # Will run at this with warnings
self.model = None

def set_model_path(self):
Expand All @@ -43,6 +44,7 @@ def initialize(self, *args, **kwargs):
tf_ratio = 1.0
else:
tf_ratio = self.vram / vram_total

logger.verbose("Reserving %s%% of total VRAM per s3fd thread",
round(tf_ratio * 100, 2))

Expand All @@ -57,8 +59,13 @@ def initialize(self, *args, **kwargs):
alloc = vram_free
logger.debug("Allocated for Tensorflow: %sMB", alloc)

self.batch_size = int(alloc / self.vram)

if self.min_vram < alloc < self.vram:
self.batch_size = 1
logger.warning("You are running s3fd with %sMB VRAM. The model is optimized for "
"%sMB VRAM. Detection should still run but you may get "
"warnings/errors", int(alloc), self.vram)
else:
self.batch_size = int(alloc / self.vram)
if self.batch_size < 1:
raise ValueError("Insufficient VRAM available to continue "
"({}MB)".format(int(alloc)))
Expand Down

0 comments on commit 86947ec

Please sign in to comment.