neuralchen / SimSwap

An arbitrary face-swapping framework on images and videos with one single trained model!
Other
4.41k stars 872 forks source link

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

Closed TransAmMan closed 3 weeks ago

TransAmMan commented 2 months ago

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.

Atieno-Ouma commented 2 months ago

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

seinfinity commented 2 months ago

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! :)

elisa5626 commented 1 month ago

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 :(

seinfinity commented 1 month ago

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? :)

orlandomendozagarrido commented 1 month ago

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
elisa5626 commented 1 month ago

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

TransAmMan commented 3 weeks ago

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 commented 3 weeks ago

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??"