Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
fix(image encoder): define use_cuda variable via args
Browse files Browse the repository at this point in the history
  • Loading branch information
felix committed Jul 17, 2019
1 parent cba5e19 commit a723630
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions gnes/encoder/image/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@ class BasePytorchEncoder(BaseImageEncoder):
def __init__(self, model_name: str,
layers: List[str],
model_dir: str,
batch_size: int = 64, *args, **kwargs):
batch_size: int = 64,
use_cuda: bool = False,
*args, **kwargs):
super().__init__(*args, **kwargs)

self.batch_size = batch_size
self.model_dir = model_dir
self.model_name = model_name
self.layers = layers
self.is_trained = True
self._use_cuda = False
self._use_cuda = use_cuda

def post_init(self):
import torch
Expand Down
6 changes: 3 additions & 3 deletions gnes/encoder/image/inception.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ class TFInceptionEncoder(BaseImageEncoder):
def __init__(self, model_dir: str,
batch_size: int = 64,
select_layer: str = 'PreLogitsFlatten',
use_gpu: bool = True,
use_cuda: bool = False,
*args, **kwargs):
super().__init__(*args, **kwargs)

self.model_dir = model_dir
self.batch_size = batch_size
self.select_layer = select_layer
self.use_gpu = use_gpu
self._use_cuda = use_cuda
self.inception_size_x = 299
self.inception_size_y = 299

Expand All @@ -54,7 +54,7 @@ def post_init(self):
dropout_keep_prob=1.0)

config = tf.ConfigProto(log_device_placement=False)
if self.use_gpu:
if self._use_cuda:
config.gpu_options.allow_growth = True
self.sess = tf.Session(config=config)
self.saver = tf.train.Saver()
Expand Down

0 comments on commit a723630

Please sign in to comment.