简体   繁体   中英

Tensorflow error: how to make tensor A the same graph as Tensor B

I'm trying to use faceswap on Google Colab to swap the faces in 2 videos following the instructions in this GitHub repo . However, when I started training the model, I got the below error message:

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

I suspect the faces images I'm using are the problem. However, I used the Extract function that comes with the repo so it should be fine? It doesn't seem to be a common issue so I suppose it's my problem. From the log, it seems the model (_base.py) isn't able to get the input_shape. But I'm not sure why. Here is the full Crash Report .

I follow exactly the steps in the GitHub USAGE.md file . Only changed the folder addresses to my own.

The command line:

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 

Training image example: Face A Face B

My code was extremely simple as I didn't write the training model myself. I looked into the _base.py, original.py, train.py file and wasn't sure what the problem is (seems to me that the input_shape wasn't passed to the model but I'm not sure it's that and not sure how I can fix it).

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

Without knowing more its difficult to say why exactly you are getting this error. My guess is use have written some extra tensorflow stuff to load your data, and this has ended up on the wrong graph. For example, the below snippet will generate the same error:

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

I guess you have made some tensors like a and are trying to use them with the provided tensors b .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM