睡前來一個— "螞蟻呀嘿",快用 ModelArts 自己也實現一個+1
根據開發者社區自己也來一個
https://mp.weixin.qq.com/s/-ZFwcdwAvJb2YSkpJS7v-A
MDG-廣州 胡琦?ModelArts AI開發者社區
點擊?https://marketplace.huaweicloud.com/markets/aihub/datasets/detail/?content_id=00bc20c3-2a00-4231-bdfd-dfa3eb62a46d 下載胡大大提供的數據集
一,先創建一個桶(用于儲存數據,也可以理解為云存儲)
桶;名全局唯一(意思可以理解為桶名只能有一個,不能有相同的)
創建完成
下載
耐心等待幾分鐘即可
登陸ModelArts控制臺https://www.huaweicloud.com/product/modelarts.html -> 開發環境 -> Notebook -> 創建
名稱:任意設置參數:python3-公共資源池-GPU-云硬盤EVS
創建Notebook
可以選擇免費的版本,但是免費的要排隊哦~
點擊提交(圈起來的是重點·~)由于我買過套餐,所以顯示的是0元
創建步驟我就直接省略了,直接啟動以及創建好的,初次創建只要選擇好GPU一般都不會出現什么問題,如果選擇cpu可能會出現內存耗盡的問題,所以建議選擇GPU~
測試一下是否能運行
print("huawei cloud")
#下載代碼,華為云代碼托管平臺再拉取 !git clone https://codehub.devcloud.cn-north-4.huaweicloud.com/ai-pome-free00001/first-order-model.git
# 此處牛刀小試--用 Moxing 下載文件 import moxing as mox # 此處需要替換您的 OBS 地址(根據實際自己的桶地址) mox.file.copy_parallel('obs://modelarts-lab/first-order-motion-model/first-order-motion-model-20210226T075740Z-001.zip' , 'first-order-motion-model.zip') mox.file.copy_parallel('obs://modelarts-lab/first-order-motion-model/02.mp4' , '02.mp4')
# 解壓 !unzip first-order-motion-model.zip
# 模版視頻 !mv 02.mp4 first-order-motion-model/
切換到first-order-model目錄,然后將?source_image_path中的路徑替換為”您的臉”所在的路徑,臉的照片可以直接通過 Notebook 的文件上傳功能上傳。
當然您還可以將默認的“螞蟻呀嘿”視頻替換為您自定義的視頻,格式為 mp4。一路執行可以查看到合成前的預覽。
cd first-order-model
import imageio import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation from skimage.transform import resize from IPython.display import HTML import warnings warnings.filterwarnings("ignore") # 此處替換為您的圖片路徑,圖片最好為 256*256,這里默認為普京大帝 source_image_path = '/home/ma-user/work/first-order-motion-model/02.png' source_image = imageio.imread(source_image_path) # 此處可替換為您的視頻路徑,這里默認為“螞蟻牙黑” reader_path = '/home/ma-user/work/first-order-motion-model/02.mp4' reader = imageio.get_reader(reader_path) # 調整圖片和視頻大小為 256x256 source_image = resize(source_image, (256, 256))[..., :3] fps = reader.get_meta_data()['fps'] driving_video = [] try: for im in reader: driving_video.append(im) except RuntimeError: pass reader.close() driving_video = [resize(frame, (256, 256))[..., :3] for frame in driving_video] def display(source, driving, generated=None): fig = plt.figure(figsize=(8 + 4 * (generated is not None), 6)) ims = [] for i in range(len(driving)): cols = [source] cols.append(driving[i]) if generated is not None: cols.append(generated[i]) im = plt.imshow(np.concatenate(cols, axis=1), animated=True) plt.axis('off') ims.append([im]) ani = animation.ArtistAnimation(fig, ims, interval=50, repeat_delay=1000) plt.close() return ani HTML(display(source_image, driving_video).to_html5_video())
from demo import load_checkpoints generator, kp_detector = load_checkpoints(config_path='config/vox-256.yaml', checkpoint_path='/home/ma-user/work/first-order-motion-model/vox-cpk.pth.tar') from demo import make_animation from skimage import img_as_ubyte predictions = make_animation(source_image, driving_video, generator, kp_detector, relative=True) # 保存結果視頻 imageio.mimsave('../generated.mp4', [img_as_ubyte(frame) for frame in predictions], fps=fps) # 在 Notebook 根目錄能找,/home/ma-user/work/ HTML(display(source_image, driving_video, predictions).to_html5_video())
# 安裝視頻剪輯神器 moviepy !pip install moviepy # 為生成的視頻加上源視頻聲音 from moviepy.editor import * videoclip_1 = VideoFileClip(reader_path) videoclip_2 = VideoFileClip("../generated.mp4") audio_1 = videoclip_1.audio videoclip_3 = videoclip_2.set_audio(audio_1) videoclip_3.write_videofile("../result.mp4", audio_codec="aac")
# 還可以給視頻加水印 video = VideoFileClip("../result.mp4") # 水印圖片請自行上傳 logo = (ImageClip("/home/ma-user/work/first-order-motion-model/water.png") .set_duration(video.duration) # 水印持續時間 .resize(height=50) # 水印的高度,會等比縮放 .margin(right=0, top=0, opacity=1) # 水印邊距和透明度 .set_pos(("left","top"))) # 水印的位置 final = CompositeVideoClip([video, logo]) final.write_videofile("../result_water.mp4", audio_codec="aac") final_reader = imageio.get_reader("../result_water.mp4") fps = final_reader.get_meta_data()['fps'] result_water_video = [] try: for im in final_reader: result_water_video.append(im) except RuntimeError: pass reader.close() result_water_video = [resize(frame, (256, 256))[..., :3] for frame in result_water_video] HTML(display(source_image, driving_video, result_water_video).to_html5_video())
我自己調用了它自己里面的一張圖片來測試
#自帶修改地址 /home/ma-user/work/first-order-motion-model/doll-07.png
AI開發平臺ModelArts 視頻
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。