目录
步骤一、下载模型
下载模型
modelscope download --model ZhipuAI/CogView4-6B --local_dir /root/autodl-tmp/ZhipuAI/CogView4-6B
安装依赖
pip install git+https://github.com/huggingface/diffusers.git
步骤二、写代码执行-英文提示词
可以成功执行的代码
from modelscope import CogView4Pipeline
from modelscope import snapshot_download
import torch
pipe = CogView4Pipeline.from_pretrained("/root/autodl-tmp/ZhipuAI/CogView4-6B", torch_dtype=torch.bfloat16)
# Open it for reduce GPU memory usage
pipe.enable_model_cpu_offload()
pipe.vae.enable_slicing()
pipe.vae.enable_tiling()
prompt = "A vibrant cherry red sports car sits proudly under the gleaming sun, its polished exterior smooth and flawless, casting a mirror-like reflection. The car features a low, aerodynamic body, angular headlights that gaze forward like predatory eyes, and a set of black, high-gloss racing rims that contrast starkly with the red. A subtle hint of chrome embellishes the grille and exhaust, while the tinted windows suggest a luxurious and private interior. The scene conveys a sense of speed and elegance, the car appearing as if it's about to burst into a sprint along a coastal road, with the ocean's azure waves crashing in the background."
image = pipe(
prompt=prompt,
guidance_scale=3.5,
num_images_per_prompt=1,
num_inference_steps=50,
width=1024,
height=1024,
).images[0]
image.save("cogview4.png")
步骤三、写代码执行-中文提示词
from modelscope import CogView4Pipeline
from modelscope import snapshot_download
import torch
pipe = CogView4Pipeline.from_pretrained("/root/autodl-tmp/ZhipuAI/CogView4-6B", torch_dtype=torch.bfloat16)
# Open it for reduce GPU memory usage
pipe.enable_model_cpu_offload()
pipe.vae.enable_slicing()
pipe.vae.enable_tiling()
prompt = "一辆充满活力的绿色跑车自豪地坐在闪闪发光的阳光下,其抛光的外观光滑无瑕,投射出镜面般的倒影。这款车的特点是低矮的空气动力学车身,有棱角的前灯,像掠食性的眼睛一样向前看,还有一套与绿色形成鲜明对比的黑色高光泽赛车轮圈。格栅和排气口上微妙的铬装饰,而有色窗户则暗示着豪华而私密的内饰。这一场景传达了一种速度和优雅的感觉,汽车看起来就像要沿着一条沿海公路冲刺,背景是大海湛蓝的海浪。"
image = pipe(
prompt=prompt,
guidance_scale=3.5,
num_images_per_prompt=1,
num_inference_steps=50,
width=1024,
height=1024,
).images[0]
image.save("cogview4-2.png")