首页 > 解决方案 > 如何从 Google Colab 运行 lua ML 模型

问题描述

我正在尝试从 Github 但在 Google Colab 上运行这种神经风格迁移模型,因为我的计算机没有足够的内存/CPU/任何东西。

我已经将我的谷歌驱动器安装到我的笔记本上,按照本教程将模型下载到我的驱动器文件夹中,将存储库克隆到我的驱动器上,为了测试它是否有效,我正在使用运行 Brad Pitt 示例的最基本示例在自述文件中使用:

th neural_style.lua -style_image examples/inputs/picasso_selfport1907.jpg -content_image examples/inputs/brad_pitt.jpg

但由于某种原因,它不起作用。

  1. 使用subprocess.run()刚刚返回No such file or directory
  2. 使用!th neural_style.lua...回报th: command not found

我已经尝试过其他四件事,它们都给了我上述两个错误消息的变体。有什么想法吗?

这是完整的笔记本代码,用于从头到尾重现我在 Colab 上的设置/错误:

# Mount the drive
from google.colab import drive
drive.mount('/content/drive')

# Clone the repo onto the drive
!git clone https://github.com/jcjohnson/neural-style

# Install Pytorch
!pip3 install http://download.pytorch.org/whl/cu80/torch-0.3.0.post4-cp36-cp36m-linux_x86_64.whl 
!pip3 install torchvision

# Download the models per the github repo instructions
!bash models/download_models.sh

!th neural_style.lua -style_image examples/inputs/picasso_selfport1907.jpg -content_image examples/inputs/brad_pitt.jpg

标签: luapytorchgoogle-colaboratory

解决方案


第一的:

%cd /content/
!git clone https://github.com/nagadomi/distro.git torch --recursive
import os
os.chdir('./torch/')
!bash install-deps
!./install.sh
!. ./install/bin/torch-activate

现在它应该使用绝对路径工作th

!/content/torch/install/bin/th neural_style.lua -style_image examples/inputs/picasso_selfport1907.jpg -content_image examples/inputs/brad_pitt.jpg

推荐阅读