shaoanlu / faceswap-GAN

A denoising autoencoder + adversarial losses and attention mechanisms for face swapping.
3.38k stars 844 forks source link

"Weight files not found" + Type error during "define_loss" #31

Closed gopowerrangers closed 6 years ago

gopowerrangers commented 6 years ago

I followed the FaceSwap_GAN_github notebook pretty closely. I was able to install all the packages expect dlib, which I believe we don't need for training.

I have two issues: 1) During "Load Models" it is throwing an error, saying that the model input has 7 layers but expects 8. I just copied over my fakeapp model. I moved on because I assumed that the program would create a new model later on. 2) During the loss_DA, loss_GA = define_loss(netDA, real_A, fake_A, vggface_feat) function, I am getting the following error stack. I would love some feedback, I am fairly new to all of this.

`--------------------------------------------------------------------------- TypeError Traceback (most recent call last)

in () ----> 1 loss_DA, loss_GA = define_loss(netDA, real_A, fake_A, vggface_feat) 2 loss_DB, loss_GB = define_loss(netDB, real_B, fake_B, vggface_feat) in define_loss(netD, real, fake, vggface_feat) 3 dist = Beta(mixup_alpha, mixup_alpha) 4 lam = dist.sample() ----> 5 mixup = lam * real + (1 - lam) * fake 6 output_mixup = netD(mixup) 7 loss_D = loss_fn(output_mixup, lam * K.ones_like(output_mixup)) ~\Anaconda3\envs\fakes\lib\site-packages\tensorflow\python\ops\math_ops.py in binary_op_wrapper(x, y) 818 with ops.name_scope(None, op_name, [x, y]) as name: 819 if not isinstance(y, sparse_tensor.SparseTensor): --> 820 y = ops.convert_to_tensor(y, dtype=x.dtype.base_dtype, name="y") 821 return func(x, y, name=name) 822 ~\Anaconda3\envs\fakes\lib\site-packages\tensorflow\python\framework\ops.py in convert_to_tensor(value, dtype, name, preferred_dtype) 637 name=name, 638 preferred_dtype=preferred_dtype, --> 639 as_ref=False) 640 641 ~\Anaconda3\envs\fakes\lib\site-packages\tensorflow\python\framework\ops.py in internal_convert_to_tensor(value, dtype, name, as_ref, preferred_dtype) 702 703 if ret is None: --> 704 ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref) 705 706 if ret is NotImplemented: ~\Anaconda3\envs\fakes\lib\site-packages\tensorflow\python\framework\constant_op.py in _constant_tensor_conversion_function(v, dtype, name, as_ref) 111 as_ref=False): 112 _ = as_ref --> 113 return constant(v, dtype=dtype, name=name) 114 115 ~\Anaconda3\envs\fakes\lib\site-packages\tensorflow\python\framework\constant_op.py in constant(value, dtype, shape, name, verify_shape) 100 tensor_value = attr_value_pb2.AttrValue() 101 tensor_value.tensor.CopyFrom( --> 102 tensor_util.make_tensor_proto(value, dtype=dtype, shape=shape, verify_shape=verify_shape)) 103 dtype_value = attr_value_pb2.AttrValue(type=tensor_value.tensor.dtype) 104 const_tensor = g.create_op( ~\Anaconda3\envs\fakes\lib\site-packages\tensorflow\python\framework\tensor_util.py in make_tensor_proto(values, dtype, shape, verify_shape) 368 nparray = np.empty(shape, dtype=np_dt) 369 else: --> 370 _AssertCompatible(values, dtype) 371 nparray = np.array(values, dtype=np_dt) 372 # check to them. ~\Anaconda3\envs\fakes\lib\site-packages\tensorflow\python\framework\tensor_util.py in _AssertCompatible(values, dtype) 300 else: 301 raise TypeError("Expected %s, got %s of type '%s' instead." % --> 302 (dtype.name, repr(mismatch), type(mismatch).__name__)) 303 304 **TypeError: Expected float32, got /input_8 of type 'TensorVariable' instead.** `
shaoanlu commented 6 years ago
  1. The weights files are not compatible with deepfakes’. But it will overwrite encoder.h5 in ./models once it starts trainung.

  2. A quick solution is to set use_mixup=False in config., this will use slightly different objective functions during training. Regarding the error, I think it has something to do with math operations on tensors (perhaps the lam or real_A variable). You can call netGA.summary() to see what exactly input_8 tensor is. Which version is your tensorflow/keras?