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

AttributeError: module 'tensorflow' has no attribute 'function' #35

Closed
zengxunli opened this issue May 21, 2022 · 3 comments
Closed

AttributeError: module 'tensorflow' has no attribute 'function' #35

zengxunli opened this issue May 21, 2022 · 3 comments

Comments

@zengxunli
Copy link

!pip install tensorflow==2.2.0(1.9.0)
!pip install h5py==2.10.0
!pip install numpy
!pip install pandas
!pip install gdown
!pip install tqdm
!pip install Pillow
!pip install opencv-python
!pip install opencv-contrib-python
!pip install keras
!pip install Flask
!pip install mtcnn
!pip install lightgbm
!pip install dlib
!pip install retina-face
!pip install deepface

from deepface import DeepFace
from retinaface import RetinaFace

faces = RetinaFace.extract_faces("ai.jpg")

print("There are ", len(faces), " faces in the image")

When I try to execute the above code, I get the following error:

AttributeError                            Traceback (most recent call last)
<ipython-input-4-f1e5ccfe8b11> in <module>
      4 import os
      5 
----> 6 faces = RetinaFace.extract_faces("ai.jpg")
      7 
      8 print("There are ", len(faces), " faces in the image")

/usr/local/lib/python3.6/site-packages/retinaface/RetinaFace.py in extract_faces(img_path, threshold, model, align, allow_upscaling)
    192     #---------------------------
    193 
--> 194     obj = detect_faces(img_path = img, threshold = threshold, model = model, allow_upscaling = allow_upscaling)
    195 
    196     if type(obj) == dict:

/usr/local/lib/python3.6/site-packages/retinaface/RetinaFace.py in detect_faces(img_path, threshold, model, allow_upscaling)
     66 
     67     if model is None:
---> 68         model = build_model()
     69 
     70     #---------------------------

/usr/local/lib/python3.6/site-packages/retinaface/RetinaFace.py in build_model()
     31     if not "model" in globals():
     32 
---> 33         model = tf.function(
     34             retinaface_model.build_model(),
     35             input_signature=(tf.TensorSpec(shape=[None, None, None, 3], dtype=np.float32),)

AttributeError: module 'tensorflow' has no attribute 'function'
@serengil
Copy link
Owner

what is your tensorflow version? I am using 2.7.0. Recommmend you to upgrade / downgrade to this version.

@zengxunli
Copy link
Author

version

My tensorflow version is 2.2.0. I have try to upgrade to this version. But I get the following error:

Looking in indexes: https://pypi.douban.com/simple
ERROR: Could not find a version that satisfies the requirement tensorflow==2.7.0
ERROR: No matching distribution found for tensorflow==2.7.0

---------------------------------------------------------------------------
InternalError                             Traceback (most recent call last)
<ipython-input-1-ee0c71cae24a> in <module>
      5 os.environ['TF_FORCE_GPU_ALLOW_GROWTH'] = 'true'
      6 
----> 7 faces = RetinaFace.extract_faces("ai.jpg")
      8 
      9 print("There are ", len(faces), " faces in the image")

/usr/local/lib/python3.6/site-packages/retinaface/RetinaFace.py in extract_faces(img_path, threshold, model, align, allow_upscaling)
    192     #---------------------------
    193 
--> 194     obj = detect_faces(img_path = img, threshold = threshold, model = model, allow_upscaling = allow_upscaling)
    195 
    196     if type(obj) == dict:

/usr/local/lib/python3.6/site-packages/retinaface/RetinaFace.py in detect_faces(img_path, threshold, model, allow_upscaling)
     88     landmarks_list = []
     89     im_tensor, im_info, im_scale = preprocess.preprocess_image(img, allow_upscaling)
---> 90     net_out = model(im_tensor)
     91     net_out = [elt.numpy() for elt in net_out]
     92     sym_idx = 0

/usr/local/lib/python3.6/site-packages/tensorflow/python/eager/def_function.py in __call__(self, *args, **kwds)
    883 
    884       with OptionalXlaContext(self._jit_compile):
--> 885         result = self._call(*args, **kwds)
    886 
    887       new_tracing_count = self.experimental_get_tracing_count()

/usr/local/lib/python3.6/site-packages/tensorflow/python/eager/def_function.py in _call(self, *args, **kwds)
    955       # If we did not create any variables the trace we have is good enough.
    956       return self._concrete_stateful_fn._call_flat(
--> 957           filtered_flat_args, self._concrete_stateful_fn.captured_inputs)  # pylint: disable=protected-access
    958 
    959     def fn_with_cond(inner_args, inner_kwds, inner_filtered_flat_args):

/usr/local/lib/python3.6/site-packages/tensorflow/python/eager/function.py in _call_flat(self, args, captured_inputs, cancellation_manager)
   1962       # No tape is watching; skip to running the function.
   1963       return self._build_call_outputs(self._inference_function.call(
-> 1964           ctx, args, cancellation_manager=cancellation_manager))
   1965     forward_backward = self._select_forward_and_backward_functions(
   1966         args,

/usr/local/lib/python3.6/site-packages/tensorflow/python/eager/function.py in call(self, ctx, args, cancellation_manager)
    594               inputs=args,
    595               attrs=attrs,
--> 596               ctx=ctx)
    597         else:
    598           outputs = execute.execute_with_cancellation(

/usr/local/lib/python3.6/site-packages/tensorflow/python/eager/execute.py in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
     58     ctx.ensure_initialized()
     59     tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
---> 60                                         inputs, attrs, num_outputs)
     61   except core._NotOkStatusException as e:
     62     if name is not None:

InternalError:  cuDNN launch failure : input shape ([1,3,1019,1980])
	 [[node model/bn_data/FusedBatchNormV3 (defined at /usr/local/lib/python3.6/site-packages/retinaface/RetinaFace.py:90) ]] [Op:__inference_function_7611]

Function call stack:
function

@serengil
Copy link
Owner

your gpu seems not properly installed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants