Préparation de l'Environnement
Cette étape consiste à préparer l'environnement sur Spell. Cette étape comprend:
- Activation de l'environnement de coding本地(本地 coding 环境配置)
- Clone the fast-style-transfer git repo from github(获取git文件):

git clone https://github.com/lengstrom/fast-style-transfer
cd fast-style-transfer
- Création de quelques folder和files(准备文件夹)
mkdir ckpt/
touch ckpt/.gitignore
mkdir images
mkdir images/style
- Put a “style” image into the images/style directory, make sure that we can actually use this artwork and we will give credit to all those images:
在images/style/这个文件里要放入需要学习的style图片。
这一步非常重要,注意版权,如果对图片版权没有把握需要谨慎,或者使用允许你用的图片
- Commit it to git (上传到git里)
git add images ckpt
git commit -m "Added required folders and images"
Téléchargement des Datasets (Environ 1 Heure)
Le dataset COCO2014 est utilisé pour la classification,因为我们需要8万张图片用来给machine学些,这步非常重要。
- run ./setup.sh (执行download data代码)
- 如果要挂载GPU需要输入如下command:
spell run --machine-type CPU ./setup.sh
运行起来需要1.5h左右。
- 在spell后台可以看见run的情况。

RUN is pending - waiting for a CPU machine
Machine a71a14603 is ready
BUILD- 100% (10/10), 0:00:02
PULL- 100% (5/5), 0:00:03
RUN - Queued
RUN is building
https://www.google.com/url?q=https://iterm2.com/
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 576M 100 576M 0 0 3405k 0 0:02:54 0:02:54 --:--:-- 3180k
需要给它一点时间。
- 准备完成!
Entraînement avec style.py (Environ 2 Heures)
This step we start train the model, it will take the machine 3-4 hours for machine learn style transfer model.
在console中输入如下命令开始train,由于需要大量GPU,推荐V100类型。
spell run \
--mount runs/THE_RUN_NUMBER_OF_YOUR_SETUP_RUN/data:datasets \
--machine-type V100 \
--framework tensorflow \
--apt ffmpeg \
--pip moviepy \
"python style.py \
--checkpoint-dir ckpt \
--style images/style/YOUR_STYLE_IMAGE_NAME.jpg \
--style-weight 1.5e2 \
--train-path datasets/train2014 \
--vgg-path datasets/imagenet-vgg-verydeep-19.mat"
Remember to replace THE_RUN_NUMBER_OF_YOUR_SETUP_RUN
and YOUR_STYLE_IMAGE_NAME
.
It took me ~2 hours. And it created files in the ckpt folder.
It will use the data from ./setup.sh
这一步时间比较长,大概2小时以上。
这个时候可以设置notiication,防止超预算。可以关注下email。
Conversion du Modèle en ml5.js
This step is final step, convert model to TensorFlow.js Model, so that we can use it inside browser. Convert tensorflow 模型到 TensorFlow.js model
- 克隆转换代码:
git clone https://github.com/reiinakano/fast-style-transfer-deeplearnjs
cd fast-style-transfer-deeplearnjs
- 需要put刚才获得的checkpoint files放到刚刚下载的文件夹:
python scripts/dump_checkpoint_vars.py \
--output_dir src/ckpts/YOUR_FOLDER_NAME
python scripts/remove_optimizer_variables.py \
--output_dir src/ckpts/YOUR_FOLDER_NAME
需要进行如下替换:
Remember to replace YOUR_FOLDER_NAME
, the folder that holds all the checkpoint files and a manifest json file.
替换成check point对应的路径名: /Users/yining/Dev/fast-style-transfer/src/ckpts/ckpt
- 开始建立tensorflow model
python -m http.server 8000