SimSwap icon indicating copy to clipboard operation
SimSwap copied to clipboard

AttributeError: module 'numpy' has no attribute 'float'

Open TransAmMan opened this issue 1 year ago • 2 comments

I am running SimSwap in Colab. I am getting an AttrbuteError, but I have no clue how to fix it.

The failure is on the last line
"video_swap(opt.video_path, latend_id, model, app, opt.output_path, temp_results_dir=opt.temp_path, use_mask=opt.use_mask)"

AttributeError: module 'numpy' has no attribute 'float'. np.float was a deprecated alias for the builtin float. To avoid this error in existing code, use float by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use np.float64 here. The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

Gemini Suggested Changes: To fix the error, replace all instances of np.float with float in the code. however I cannot find places in the code to make the change.

TransAmMan avatar May 31 '24 14:05 TransAmMan

I also getting the above error,anyone know how to go about it?

Atieno-Ouma avatar Jun 10 '24 11:06 Atieno-Ouma

Here's a suggested response to the GitHub issue regarding the AttributeError related to np.float:


I encountered the same AttributeError: module 'numpy' has no attribute 'float' issue while running SimSwap in Colab. The error occurs because np.float was deprecated in NumPy 1.20 and later removed.

I found a solution by downgrading the NumPy version from 1.25.2 to 1.23.5. Here are the steps I followed:

  1. Downgrade NumPy to version 1.23.5:

    pip install numpy==1.23.5
    
  2. Restart the Colab session to apply the changes.

After performing these steps, the code ran successfully without the AttributeError.

I hope this helps anyone facing the same issue! :)

seinfinity avatar Jun 18 '24 00:06 seinfinity

Here's a suggested response to the GitHub issue regarding the AttributeError related to np.float:

I encountered the same AttributeError: module 'numpy' has no attribute 'float' issue while running SimSwap in Colab. The error occurs because np.float was deprecated in NumPy 1.20 and later removed.

I found a solution by downgrading the NumPy version from 1.25.2 to 1.23.5. Here are the steps I followed:

  1. Downgrade NumPy to version 1.23.5:
    pip install numpy==1.23.5
    
  2. Restart the Colab session to apply the changes.

After performing these steps, the code ran successfully without the AttributeError.

I hope this helps anyone facing the same issue! :)

Thank you so much....but exactly where can I put pip install numpy==1.23.5 ? sorry for the stupid question :(

elisa5626 avatar Jul 05 '24 06:07 elisa5626

Thank you so much....but exactly where can I put pip install numpy==1.23.5 ? sorry for the stupid question :(

Can you tell me what environment you’re running the code in? Are you using venv or conda? :)

seinfinity avatar Jul 05 '24 06:07 seinfinity

on the left side of the colab click on the simswap folder, scroll down to the util folder look for the reverse2original.py file, line 157 -160 replace it with the code below and then reinstall everything and run and its good to go.

In the file /content/SimSwap/util/reverse2original.py

if use_mask:
    target_image = np.array(target_image, dtype=float) * 255  # Change np.float to float
else:
    target_image = np.array(target_image, dtype=float)[..., ::-1] * 255  # Change np.float to float

orlandomendozagarrido avatar Jul 13 '24 05:07 orlandomendozagarrido

on the left side of the colab click on the simswap folder, scroll down to the util folder look for the reverse2original.py file, line 157 -160 replace it with the code below and then reinstall everything and run and its good to go.

In the file /content/SimSwap/util/reverse2original.py

if use_mask:
    target_image = np.array(target_image, dtype=float) * 255  # Change np.float to float
else:
    target_image = np.array(target_image, dtype=float)[..., ::-1] * 255  # Change np.float to float

i tried ( i changed line 168 too) but i get this error message:

AttributeError Traceback (most recent call last) in <cell line: 22>() 39 latend_id = latend_id.to('cuda') 40 ---> 41 video_swap(opt.video_path, latend_id, model, app, opt.output_path, temp_results_dir=opt.temp_path, use_mask=opt.use_mask)

2 frames /usr/local/lib/python3.10/dist-packages/numpy/init.py in getattr(attr) 317 318 if attr in former_attrs: --> 319 raise AttributeError(former_attrs[attr]) 320 321 if attr == 'testing':

AttributeError: module 'numpy' has no attribute 'float'. np.float was a deprecated alias for the builtin float. To avoid this error in existing code, use float by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use np.float64 here. The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

elisa5626 avatar Jul 24 '24 06:07 elisa5626

Here's a suggested response to the GitHub issue regarding the AttributeError related to np.float:

I encountered the same AttributeError: module 'numpy' has no attribute 'float' issue while running SimSwap in Colab. The error occurs because np.float was deprecated in NumPy 1.20 and later removed.

I found a solution by downgrading the NumPy version from 1.25.2 to 1.23.5. Here are the steps I followed:

  1. Downgrade NumPy to version 1.23.5:
    pip install numpy==1.23.5
    
  2. Restart the Colab session to apply the changes.

After performing these steps, the code ran successfully without the AttributeError.

I hope this helps anyone facing the same issue! :)

Thank you elisa5626 I tried every way to implement this, but was not successful. What I found that NumPy is installed as part of other packages, and the 1.23.5 version is overwriten. Also if you If you could elaborate on how you did this, it would help.

TransAmMan avatar Aug 04 '24 17:08 TransAmMan

on the left side of the colab click on the simswap folder, scroll down to the util folder look for the reverse2original.py file, line 157 -160 replace it with the code below and then reinstall everything and run and its good to go.

In the file /content/SimSwap/util/reverse2original.py

if use_mask:
    target_image = np.array(target_image, dtype=float) * 255  # Change np.float to float
else:
    target_image = np.array(target_image, dtype=float)[..., ::-1] * 255  # Change np.float to float

Thank you orlandomendozagarrido I tried your change. I may be doing it wrong, but I found that if I "reinstall everything and run" a new, original, file is loaded and the change is lost, or not used. I may be missing something maybe you mean "reinstall a single cell??"

TransAmMan avatar Aug 04 '24 17:08 TransAmMan