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

Running without GPU #180

Open
castelli666 opened this issue Dec 16, 2021 · 6 comments
Open

Running without GPU #180

castelli666 opened this issue Dec 16, 2021 · 6 comments

Comments

@castelli666
Copy link

Hi...first congratulation si really efficient and smart...I would like to know if there is any parameter that will allow me to use it only on CPU (no nvidia)...or a trick/emulator
Thanks a lot

@Echolink50
Copy link

I tried it. It looks for the Nvidia drivers when you run it. It may work if you manually installed in Nvidia drivers into the proper folders. I wasn't getting any GPU usage anyway so I tried it on another computer that doesn't have a GPU. It's just an i7. If you get it to run without a GPU let us know. You can also just use the Google colab.

@illtellyoulater
Copy link

illtellyoulater commented Jan 6, 2022

According to #61 by patching the files with the script at https://pastebin.com/y1FxV8jA you can make it run only on the CPU (no GPU needed at all).

Also at the following repository https://github.com/johndpope/SimSWAP-docker you can find a dockerfile for building a Simswap docker image which if I remember correctly is already patched with the method above. The image is not using the latest version of Simswap but the penultimate one, but that's not a problem as the improvements in the latest version model does not seem to produce better results (see #171).

Update: a new repository has been published by the same user at https://github.com/johndpope/SimSWAP-docker-1 which uses the latest version of Simswap. If you want you could still run this latest version with the old, better-looking model by using the "--crop_size 224" parameter.

@tikitong
Copy link

tikitong commented Sep 20, 2022

Hello, I put here the installation command lines that worked for me (MacOS Apple Chip M1). Also for CPU usage only with the Powershell script available here: https://pastebin.com/y1FxV8jA, thanks a lot for that #61, @illtellyoulater for links and #294.

Here is my configuration: macOS-12.5.1-arm64-arm-64bit

Assuming you have installed brew. Hope this help.

brew install wget 
brew install ffmpeg
sudo softwareupdate --install-rosetta
brew install --cask powershell

conda create -n simswap python=3.9
conda activate simswap

conda install pytorch torchvision -c pytorch-nightly
conda install -c conda-forge protobuf numpy
pip install onnx  
pip install insightface==0.2.1 onnxruntime moviepy
pip install --ignore-installed imageio

git clone https://github.com/neuralchen/SimSwap
cd SimSwap && git pull 

wget -P ./arcface_model https://github.com/neuralchen/SimSwap/releases/download/1.0/arcface_checkpoint.tar

wget https://github.com/neuralchen/SimSwap/releases/download/1.0/checkpoints.zip

unzip ./checkpoints.zip  -d ./checkpoints

wget -P ./parsing_model/checkpoint https://github.com/neuralchen/SimSwap/releases/download/1.0/79999_iter.pth

wget --no-check-certificate "https://sh23tw.dm.files.1drv.com/y4mmGiIkNVigkSwOKDcV3nwMJulRGhbtHdkheehR5TArc52UjudUYNXAEvKCii2O5LAmzGCGK6IfleocxuDeoKxDZkNzDRSt4ZUlEt8GlSOpCXAFEkBwaZimtWGDRbpIGpb_pz9Nq5jATBQpezBS6G_UtspWTkgrXHHxhviV2nWy8APPx134zOZrUIbkSF6xnsqzs3uZ_SEX_m9Rey0ykpx9w" -O antelope.zip

unzip ./antelope.zip -d ./insightface_func/models/

pwsh patch.ps1 # FOR CPU ONLY assuming you have downloaded the file at https://pastebin.com/y1FxV8jA 

python test_video_swapsingle.py --crop_size 224 --use_mask --name people --Arc_path arcface_model/arcface_checkpoint.tar --pic_a_path demo_file/Iron_man.jpg --video_path demo_file/multi_people_1080p.mp4 --output_path output/multi_test_swapsingle.mp4 --temp_path temp_results

------------ Options -------------
Arc_path: arcface_model/arcface_checkpoint.tar
aspect_ratio: 1.0
batchSize: 8
checkpoints_dir: ./checkpoints
cluster_path: features_clustered_010.npy
crop_size: 224
data_type: 32
dataroot: ./datasets/cityscapes/
display_winsize: 512
engine: None
export_onnx: None
feat_num: 3
fineSize: 512
fp16: False
gpu_ids: [0]
how_many: 50
id_thres: 0.03
image_size: 224
input_nc: 3
instance_feat: False
isTrain: False
label_feat: False
label_nc: 0
latent_size: 512
loadSize: 1024
load_features: False
local_rank: 0
max_dataset_size: inf
model: pix2pixHD
multisepcific_dir: ./demo_file/multispecific
nThreads: 2
n_blocks_global: 6
n_blocks_local: 3
n_clusters: 10
n_downsample_E: 4
n_downsample_global: 3
n_local_enhancers: 1
name: people
nef: 16
netG: global
ngf: 64
niter_fix_global: 0
no_flip: False
no_instance: False
no_simswaplogo: False
norm: batch
norm_G: spectralspadesyncbatch3x3
ntest: inf
onnx: None
output_nc: 3
output_path: output/multi_test_swapsingle.mp4
phase: test
pic_a_path: demo_file/Iron_man.jpg
pic_b_path: ./crop_224/zrf.jpg
pic_specific_path: ./crop_224/zrf.jpg
resize_or_crop: scale_width
results_dir: ./results/
semantic_nc: 3
serial_batches: False
temp_path: temp_results
tf_log: False
use_dropout: False
use_encoded_image: False
use_mask: True
verbose: False
video_path: demo_file/multi_people_1080p.mp4
which_epoch: latest
-------------- End ----------------
input mean and std: 127.5 127.5
find model: ./insightface_func/models/antelope/glintr100.onnx recognition
find model: ./insightface_func/models/antelope/scrfd_10g_bnkps.onnx detection
set det-size: (640, 640)
(142, 366, 4)
  1%|▎                                          | 5/594 [00:04<09:31,  1.03it/s]  
  1%|▎      

@escamez
Copy link

escamez commented Dec 7, 2022

Hi there,

Thanks very much for the detailed installation guide, I just followed your instructions step by step, but on a newer OS version, actually: MacOS 13.0 (MacBook Pro M1) and I keep getting this error:

/opt/homebrew/Caskroom/miniforge/base/envs/simswap/lib/python3.9/site-packages/torchvision/io/image.py:13: 
UserWarning: Failed to load image Python extension: dlopen(/opt/homebrew/Caskroom/miniforge/base/envs/simswap/lib/python3.9/site-packages/torchvision/image.so, 0x0006): 
symbol not found in flat namespace '__ZN2at4_ops19empty_memory_format4callEN3c108ArrayRefIxEENS2_8optionalINS2_10ScalarTypeEEENS5_INS2_6LayoutEEENS5_INS2_6DeviceEEENS5_IbEENS5_INS2_12MemoryFormatEEE'
  warn(f"Failed to load image Python extension: {e}")

------------ Options -------------
Arc_path: arcface_model/arcface_checkpoint.tar
aspect_ratio: 1.0
batchSize: 8
checkpoints_dir: ./checkpoints
cluster_path: features_clustered_010.npy
crop_size: 224
data_type: 32
dataroot: ./datasets/cityscapes/
display_winsize: 512
engine: None
export_onnx: None
feat_num: 3
fineSize: 512
fp16: False
gpu_ids: [0]
how_many: 50
id_thres: 0.03
image_size: 224
input_nc: 3
instance_feat: False
isTrain: False
label_feat: False
label_nc: 0
latent_size: 512
loadSize: 1024
load_features: False
local_rank: 0
max_dataset_size: inf
model: pix2pixHD
multisepcific_dir: ./demo_file/multispecific
nThreads: 2
n_blocks_global: 6
n_blocks_local: 3
n_clusters: 10
n_downsample_E: 4
n_downsample_global: 3
n_local_enhancers: 1
name: people
nef: 16
netG: global
ngf: 64
niter_fix_global: 0
no_flip: False
no_instance: False
no_simswaplogo: False
norm: batch
norm_G: spectralspadesyncbatch3x3
ntest: inf
onnx: None
output_nc: 3
output_path: output/multi_test_swapsingle.mp4
phase: test
pic_a_path: demo_file/Iron_man.jpg
pic_b_path: ./crop_224/zrf.jpg
pic_specific_path: ./crop_224/zrf.jpg
resize_or_crop: scale_width
results_dir: ./results/
semantic_nc: 3
serial_batches: False
temp_path: temp_results
tf_log: False
use_dropout: False
use_encoded_image: False
use_mask: True
verbose: False
video_path: demo_file/multi_people_1080p.mp4
which_epoch: latest
-------------- End ----------------
Traceback (most recent call last):
  File "/Users/escamez/Devel/workspaces/workspace.escamez/SimSwap/test_video_swapsingle.py", line 54, in <module>
    model = create_model(opt)
  File "/Users/escamez/Devel/workspaces/workspace.escamez/SimSwap/models/models.py", line 18, in create_model
    model.initialize(opt)
  File "/Users/escamez/Devel/workspaces/workspace.escamez/SimSwap/models/fs_model.py", line 67, in initialize
    netArc_checkpoint = torch.load(netArc_checkpoint) if torch.cuda.is_available() else torch.load(netArc_checkpoint, map_location=torch.device('cpu'))
  File "/opt/homebrew/Caskroom/miniforge/base/envs/simswap/lib/python3.9/site-packages/torch/serialization.py", line 795, in load
    return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
  File "/opt/homebrew/Caskroom/miniforge/base/envs/simswap/lib/python3.9/site-packages/torch/serialization.py", line 1012, in _legacy_load
    result = unpickler.load()
  File "/opt/homebrew/Caskroom/miniforge/base/envs/simswap/lib/python3.9/site-packages/torch/optim/sgd.py", line 112, in __setstate__
    super().__setstate__(state)
  File "/opt/homebrew/Caskroom/miniforge/base/envs/simswap/lib/python3.9/site-packages/torch/optim/optimizer.py", line 84, in __setstate__
    self.defaults.setdefault('differentiable', False)
AttributeError: 'SGD' object has no attribute 'defaults'

I checked that MPS is enabled with jupyter notebook etc, so I've no idea what this error is about.

Did you ever encounter this issue?.

Thanks in advance

@tikitong
Copy link

tikitong commented Dec 8, 2022

Hi @escamez, this may be related to Pytorch's version. I can't say exactly where this error comes from. Without going through pytorch-nightly unfortunately, try to replace:

conda install pytorch torchvision -c pytorch-nightly
conda install -c conda-forge protobuf numpy
pip install onnx  
pip install insightface==0.2.1 onnxruntime moviepy
pip install --ignore-installed imageio

by

conda install pytorch==1.12.0 torchvision==0.13.0 torchaudio==0.12.0 -c pytorch
pip install onnx insightface==0.2.1 onnxruntime moviepy imageio imageio-ffmpeg 

during the installation process. Please let me know if it's work! I will find out more about your error raised.

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

No branches or pull requests

6 participants