python - tensorflow 错误: how to make tensor A the same graph as Tensor B

标签 python tensorflow google-colaboratory

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

Tensor("conv2d_9/kernel:0", shape=(5, 5, 3, 128), dtype=float32_ref) must be from the same graph as 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

最佳答案

在不了解更多信息的情况下,很难确切地说出为什么会出现此错误。我的猜测是使用编写了一些额外的 tensorflow 内容来加载您的数据,但这最终出现在错误的图表上。例如,下面的代码片段将生成相同的错误:

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

关于python - tensorflow 错误: how to make tensor A the same graph as Tensor B,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56471368/

相关文章:

tensorflow - 无法从命令提示符运行 Tensorboard

google-colaboratory - 在 colab 中导入与您共享/由您共享的 Google 云端硬盘文件

python-3.x - Google Colab 导致本地内存占用过高?

Python将字符串拆分为下一个句号标点符号

python - 在 Mac 上使用 isql 和 python 连接到远程 MSSQL 2016?

python - Python 的 csv.reader(filename) 真的返回一个列表吗?好像不是

python - 准确找到最小的特征值

python - 如何将GPU上训练的模型加载到CPU(系统)内存中?

python - TensorFlow: "No gradients provided for any variable"和 partial_run

python - 谷歌 Colab TPU 版本