【问题标题】:Tensorflow error: how to make tensor A the same graph as Tensor BTensorflow错误:如何使张量A与张量B相同的图
【发布时间】:2023-03-22 05:39:01
【问题描述】:

我正在按照this GitHub repo 中的说明尝试在 Google Colab 上使用 faceswap 来交换 2 个视频中的面孔。但是,当我开始训练模型时,我收到以下错误消息:

Tensor("conv2d_9/kernel:0", shape=(5, 5, 3, 128), dtype=float32_ref) 必须与 Tensor("face:0", shape=(?, 64) 来自同一个图, 64, 3), dtype=float32).

我怀疑我使用的面孔图像是问题所在。但是,我使用了 repo 附带的 Extract 函数,所以应该没问题吗?这似乎不是一个普遍的问题,所以我想这是我的问题。从日志来看,模型(_base.py)似乎无法获取 input_shape。但我不确定为什么。这是完整的Crash Report

我完全按照GitHub USAGE.md file 中的步骤进行操作。只是把文件夹地址改成了我自己的。

命令行:

faceswap.py train -A /content/drive/My Drive/Colab Projects/Trump_faces -B /content/drive/My Drive/Colab Projects/Alan_faces -m /content/drive/My Drive/Colab 

训练图像示例: Face A Face B

我的代码非常简单,因为我自己没有编写训练模型。我查看了 _base.py、original.py、train.py 文件,但不确定问题出在哪里(在我看来,input_shape 没有传递给模型,但我不确定是不是这样,也不确定我该如何解决它)。

from google.colab import drive
drive.mount('/content/drive', force_remount = True)
!git clone https://github.com/deepfakes/faceswap.git
% cd '/content/drive/My Drive/Colab Projects'
% cd '/content/drive/My Drive/Colab Projects/faceswap'
!pip install folium==0.2.1
!pip install imgaug==0.2.5
!python setup.py
!python faceswap.py extract -i '/content/drive/My Drive/Colab Projects/Trump_images' -o '/content/drive/My Drive/Colab Projects/Trump_faces'
!python faceswap.py extract -i '/content/drive/My Drive/Colab Projects/Another_images' -o '/content/drive/My Drive/Colab Projects/Another_faces'
!python faceswap.py train -A 'Trump_faces' -B 'Another_faces' -m 'Face_Swap_Model' -p

【问题讨论】:

    标签: python tensorflow google-colaboratory


    【解决方案1】:

    如果不了解更多信息,很难说出您收到此错误的确切原因。我的猜测是使用已经编写了一些额外的 tensorflow 内容来加载您的数据,而这最终出现在错误的图表上。例如下面的 sn -p 会产生同样的错误:

    import tensorflow as tf
    
    first_graph = tf.Graph()
    
    # add tensor a to graph first_graph
    with first_graph.as_default():
        a = tf.constant([1])
    
    # puts b on default_graph, seperate from the first_graph
    b = tf.constant([2])
    
    # error! cannot do anything together as they belong to different graphs
    c = a*b
    

    我猜您已经创建了一些张量,例如 a,并尝试将它们与提供的张量 b 一起使用。

    【讨论】:

    • 谢谢,本!实际上,我拥有的所有代码都非常简单,因为我自己没有编写训练模型。我在描述中添加了代码。我检查了主仓库中的脚本,似乎张量 B 应该采用张量 A 的形状,但不知何故失败了。只是不知道为什么我似乎是唯一一个得到这个错误的人。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-13
    • 1970-01-01
    • 2022-07-20
    • 2019-09-02
    • 1970-01-01
    相关资源
    最近更新 更多