Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't create more than one instance of MTCNN class #7

Closed
lshostenko opened this issue May 12, 2018 · 2 comments
Closed

Can't create more than one instance of MTCNN class #7

lshostenko opened this issue May 12, 2018 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@lshostenko
Copy link

Creating another instance of MTCNN causes a tensorflow error. Seems like they are trying to share the same tf session:

from mtcnn.mtcnn import MTCNN

detector_1 = MTCNN(steps_threshold=(.2, .7, .7))  # ok
detector_2 = MTCNN(steps_threshold=(.1, .7, .5))  # error
ValueError                                Traceback (most recent call last)
<ipython-input-3-62d11dc62821> in <module>()
----> 1 detector_2 = MTCNN(steps_threshold=(.1, .7, .5))

~/py/ocean/test/env/lib/python3.6/site-packages/mtcnn/mtcnn.py in __init__(self, weights_file, min_face_size, steps_threshold, scale_factor)
    191
    192         weights = np.load(weights_file).item()
--> 193         self.__pnet = PNet(self.__session, False)
    194         self.__pnet.set_weights(weights['PNet'])
    195

~/py/ocean/test/env/lib/python3.6/site-packages/mtcnn/network.py in __init__(self, session, trainable)
     42
     43         with tf.variable_scope(self.__class__.__name__.lower()):
---> 44             self._config()
     45
     46     def _config(self):

~/py/ocean/test/env/lib/python3.6/site-packages/mtcnn/mtcnn.py in _config(self)
     53         layer_factory.new_feed(name='data', layer_shape=(None, None, None, 3))
     54         layer_factory.new_conv(name='conv1', kernel_size=(3, 3), channels_output=10, stride_size=(1, 1),
---> 55                                padding='VALID', relu=False)
     56         layer_factory.new_prelu(name='prelu1')
     57         layer_factory.new_max_pool(name='pool1', kernel_size=(2, 2), stride_size=(2, 2))

~/py/ocean/test/env/lib/python3.6/site-packages/mtcnn/layer_factory.py in new_conv(self, name, kernel_size, channels_output, stride_size, padding, group, biased, relu, input_layer_name)
    121
    122         with tf.variable_scope(name) as scope:
--> 123             kernel = self.__make_var('weights', shape=[kernel_size[1], kernel_size[0], channels_input // group, channels_output])
    124
    125             output = convolve(input_layer, kernel)

~/py/ocean/test/env/lib/python3.6/site-packages/mtcnn/layer_factory.py in __make_var(self, name, shape)
     76         :return: created TF variable.
     77         """
---> 78         return tf.get_variable(name, shape, trainable=self.__network.is_trainable())
     79
     80     def new_feed(self, name: str, layer_shape: tuple):

~/py/ocean/test/env/lib/python3.6/site-packages/tensorflow/python/ops/variable_scope.py in get_variable(name, shape, dtype, initializer, regularizer, trainable, collections, caching_device, partitioner, validate_shape, use_resource, custom_getter, constraint)
   1315       partitioner=partitioner, validate_shape=validate_shape,
   1316       use_resource=use_resource, custom_getter=custom_getter,
-> 1317       constraint=constraint)
   1318 get_variable_or_local_docstring = (
   1319     """%s

~/py/ocean/test/env/lib/python3.6/site-packages/tensorflow/python/ops/variable_scope.py in get_variable(self, var_store, name, shape, dtype, initializer, regularizer, reuse, trainable, collections, caching_device, partitioner, validate_shape, use_resource, custom_getter, constraint)
   1077           partitioner=partitioner, validate_shape=validate_shape,
   1078           use_resource=use_resource, custom_getter=custom_getter,
-> 1079           constraint=constraint)
   1080
   1081   def _get_partitioned_variable(self,

~/py/ocean/test/env/lib/python3.6/site-packages/tensorflow/python/ops/variable_scope.py in get_variable(self, name, shape, dtype, initializer, regularizer, reuse, trainable, collections, caching_device, partitioner, validate_shape, use_resource, custom_getter, constraint)
    423           caching_device=caching_device, partitioner=partitioner,
    424           validate_shape=validate_shape, use_resource=use_resource,
--> 425           constraint=constraint)
    426
    427   def _get_partitioned_variable(

~/py/ocean/test/env/lib/python3.6/site-packages/tensorflow/python/ops/variable_scope.py in _true_getter(name, shape, dtype, initializer, regularizer, reuse, trainable, collections, caching_device, partitioner, validate_shape, use_resource, constraint)
    392           trainable=trainable, collections=collections,
    393           caching_device=caching_device, validate_shape=validate_shape,
--> 394           use_resource=use_resource, constraint=constraint)
    395
    396     if custom_getter is not None:

~/py/ocean/test/env/lib/python3.6/site-packages/tensorflow/python/ops/variable_scope.py in _get_single_variable(self, name, shape, dtype, initializer, regularizer, partition_info, reuse, trainable, collections, caching_device, validate_shape, use_resource, constraint)
    731                          "reuse=tf.AUTO_REUSE in VarScope? "
    732                          "Originally defined at:\n\n%s" % (
--> 733                              name, "".join(traceback.format_list(tb))))
    734       found_var = self._vars[name]
    735       if not shape.is_compatible_with(found_var.get_shape()):

ValueError: Variable pnet/conv1/weights already exists, disallowed. Did you mean to set reuse=True or reuse=tf.AUTO_REUSE in VarScope? Originally defined at:

  File "/Users/erizo/py/ocean/test/env/lib/python3.6/site-packages/mtcnn/layer_factory.py", line 78, in __make_var
    return tf.get_variable(name, shape, trainable=self.__network.is_trainable())
  File "/Users/erizo/py/ocean/test/env/lib/python3.6/site-packages/mtcnn/layer_factory.py", line 123, in new_conv
    kernel = self.__make_var('weights', shape=[kernel_size[1], kernel_size[0], channels_input // group, channels_output])
  File "/Users/erizo/py/ocean/test/env/lib/python3.6/site-packages/mtcnn/mtcnn.py", line 55, in _config
    padding='VALID', relu=False)
@ipazc ipazc self-assigned this May 12, 2018
@ipazc ipazc added the bug Something isn't working label May 12, 2018
@ipazc
Copy link
Owner

ipazc commented May 12, 2018

This is the cause of the issue #6

ipazc added a commit that referenced this issue May 12, 2018
@ipazc
Copy link
Owner

ipazc commented May 12, 2018

Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants