prefacio
Recientemente vi un proyecto más interesante, que puede generar pinturas abstractas correspondientes a partir de fotos.
Dirección del proyecto: dirección de github
Eche un vistazo a las representaciones proporcionadas por el proyecto.
¿No es muy interesante? Decidí bajar el proyecto y jugarlo yo mismo. A continuación les comparto el proceso de instalación y uso para su referencia.
Instalar en pc
Primero veamos las instrucciones de instalación dadas por el autor.
El autor proporciona el modo de instalación de docker y el modo de instalación de pip. Usé pip para la instalación y el despliegue en muchos artículos anteriores. Esta vez decidí ser perezoso y usar el método docker. Hablemos de mi proceso de instalación por turnos y mostrémoslo a los estudiantes que no lo han hecho.
tirar de la imagen
De acuerdo con la orden del autor, extraiga la imagen en el servidor preparado con tarjeta gráfica.
ventana acoplable tirar yaelvinker/clipasso_docker
Este comando lleva mucho tiempo, tienes que esperar un poco más.
iniciar el contenedor
Una vez que se completa la extracción del espejo, el comando de inicio que uso es el siguiente:
docker run --name=hy-c -itd --restart=siempre --gpus all --shm-size 16G -p 2281:22 --log-opt max-size=50m --log-opt max-file= 10 yaelvinker/clipasso_docker
No seguí el orden proporcionado por el autor, lo explicaré aquí.
1. Asigne principalmente la tarjeta gráfica externa al contenedor.
2. Asigne el puerto 22 al puerto externo 2281 para la depuración local de pycharm. Si está interesado, consulte
Depuración de ejecución del contenedor acoplable de código Pycharm
Si no necesita una depuración similar, puede eliminar esta parte del comando.
sacar proyecto
cd /home
git clone https://github.com/yael-vinker/CLIPasso.git
cd CLIPasso/
复制代码
La estructura del directorio es la siguiente
utilizar
Antes de usarlo, echemos un vistazo a algunas explicaciones de parámetros dadas por el autor.
Argumentos opcionales:
--num_strokes
Defines the number of strokes used to create the sketch, which determines the level of abstraction. The default value is set to 16, but for different images, different numbers might produce better results.--mask_object
It is recommended to use images without a background, however, if your image contains a background, you can mask it out by using this flag with "1" as an argument.--fix_scale
If your image is not squared, it might be cut off, it is recommended to use this flag with 1 as input to automatically fix the scale without cutting the image.--num_sketches
As stated in the paper, by default there will be three parallel running scripts to synthesize three sketches and automatically choose the best one. However, for some environments (for example when running on CPU) this might be slow, so you can specify --num_sketches 1 instead.-cpu
If you want to run the code on the cpu (not recommended as it might be very slow).
简单说明一下
1、第一个参数--num_strokes主要是用来标识笔画数等级的,默认为16。简而言之,数量越大,画面越详细,数量越小,画面越抽象。
2、第二个参数--mask_object是用来扣除背景的,如果需要的话,使用1。
3、第三个参数--fix_scale是用来配置是否需要切图的,如果不配置的话,项目会先将图片转化为1:1的分辨率,如果想要保持原来的分辨率,需要配置为1。
4、第四个参数--num_sketches,默认为跑3次选最好的一次,如果你只想要1次,配置1就行。
5、第五个参数是否使用CPU,就不细说了。
样例一
下面是准备的第一张图,背景为纯白色。
执行命令如下
python run_object_sketching.py --target_file "changjinglu.jpg"
复制代码
执行结果
看一下效果
可以看出跑了3次。
还挺有意思的,大致的轮廓还是比较清晰的。
样例二
第二张图我挑了一张有背景的。
执行命令如下
python run_object_sketching.py --target_file "redainiao.jpg" --num_strokes 8 --num_sketches 1 --mask_object 1 --fix_scale 1
复制代码
参数上,我减少了笔画数,并且需要扣除一下背景以及保留原比例。
执行结果
看一下效果
整体形象还是非常不错的,很清晰的看出鸟的轮廓。
样例三
第三幅图我找了一张蒙娜丽莎的画像,主要想看看不扣背景,油画的抽象画效果。
执行命令如下
python run_object_sketching.py --target_file "mengnalisha.jpg" --num_strokes 32 --num_sketches 1 --fix_scale 1
复制代码
参数上,我增加了一些笔画,保留比例且不扣背景。
执行结果
看一下效果
哈哈哈,很有喜感,虽然效果不是很好,可能和我设置的笔画数太少有关。留个悬念,大家有兴趣可以加多一些笔画数看看效果。
补充(很关键)
注意看一下这部分代码。
在容器化部署安装过程中,镜像是带有该预处理模型的。如果pip安装的话,需要自己下载,google云盘,懂得都懂。所以我把模型放到我的百度云盘上,需要的也可以从下面的链接下载。
链接:pan.baidu.com/s/1sHDJu8XS… 提取码:TUAN
总结
Ha pasado mucho tiempo desde que escribí la serie de aprendizaje automático. De hecho, he recopilado muchos proyectos interesantes en github y los jugaré cuando tenga tiempo. Si tiene tiempo, puede convertir el proyecto en una herramienta y compartirlo, pero recientemente he estado ocupado y estoy investigando cosas nuevas.
Cuota:
Yet high over the city our line of yellow windows must have contributed their share of human secrecy to the casual watcher in the darkening streets, and I was him too, looking up and wondering. I was within and without, simultaneously enchanted and repelled by the inexhaustible variety of life.——《了不起的盖茨比》
复制代码
Si este artículo te fue útil, dale a Me gusta, ¡gracias!
La dirección de mi página de inicio de CSDN : Página de inicio del espadachín ALiang_ALiang
Aprender juntos y progresar juntos.