Tensorflow错误:如何使张量A与张量B相同的图

时间:2019-06-06 05:29:42

标签: python tensorflow google-colaboratory

我正在尝试按照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

1 个答案:

答案 0 :(得分:0)

在不知道更多信息的情况下很难说出您究竟为什么收到此错误。我的猜测是,使用了一些额外的张量流东西来加载数据,这最终在错误的图形上结束了。例如,以下代码段将产生相同的错误:

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一起使用。