在Google Colab中尝试其他源图像后出现ValueError

问题描述

最近,我一直在尝试使用Aliaksandr Siarohin制作的“一阶运动模型”方法制作Deepfake视频(使用与https://colab.research.google.com/github/AliaksandrSiarohin/first-order-model/blob/master/demo.ipynb类似的演示,使用Google Colab /笔记本)

一切进展顺利,直到我决定制作第二个Deepfake视频,这次使用不同的“源图像”(请参见代码002.jpg)。更改源图像后,我遇到以下ValueError:

ValueError:所有输入数组的维数必须相同,但索引0的数组具有2个维,索引1的数组具有3个维

问题显然出在第33行:

im = plt.imshow(np.concatenate(cols,axis = 1),animation = True)

代码

!pip install scikit-video
import skvideo.io  
driving_video = skvideo.io.vread("/content/gdrive/My Drive/first-order-motion-model/huhu.mp4") 
print(driving_video.shape)

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")

source_image = imageio.imread('/content/gdrive/My Drive/first-order-motion-model/002.jpg')

#Resize image and video to 256x256

source_image = resize(source_image,(256,256))[...,:3]
driving_video = [resize(frame,: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())

我成功地用另一个图像运行代码后出现了这个错误,这使我认为问题出在图像上。我再次尝试了第一个图像(001.jpg),但ValueError没有出现。所以我的问题是,我需要对图像进行什么更改,以便给定的代码起作用?还是代码本身有些奇怪?我检查了文件大小(12KB),实际上小于我以前使用的文件大小(31KB)。宽度和高度也相距不远(新图片为218x300,旧图片为384x512)。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)