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

automatic choose gpu or cpu #46

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ def write_video_with_audio(audio_path, output_path, prefix='pred_'):
############################### I/O Settings ##############################
# load config files
opt = parser.parse_args()
device = torch.device(opt.device)
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

if torch.cuda.is_available():
map_location=lambda storage, loc: storage.cuda()
else:
map_location='cpu'

with open(join('./config/', opt.id + '.yaml')) as f:
config = yaml.load(f)
data_root = join('./data/', opt.id)
Expand Down Expand Up @@ -147,7 +153,7 @@ def write_video_with_audio(audio_path, output_path, prefix='pred_'):
config['model_params']['APC']['hidden_size'],
config['model_params']['APC']['num_layers'],
config['model_params']['APC']['residual'])
APC_model.load_state_dict(torch.load(config['model_params']['APC']['ckp_path']), strict=False)
APC_model.load_state_dict(torch.load(config['model_params']['APC']['ckp_path'],map_location=map_location), strict=False)
if opt.device == 'cuda':
APC_model.cuda()
APC_model.eval()
Expand Down