albertlai / deep-style-transfer

🖼 Tensorflow implementation of a fast feed-forward neural style transfer network
45 stars 21 forks source link

Trouble styling based on Trained model #3

Closed gaylejj closed 6 years ago

gaylejj commented 7 years ago

I'm trying to style an image based on a model I trained, but keep getting a Tensorflow error about not being able to find the Tensor.

transfererror

I tried specifying the model file in the arguments as --model_file=./diving.pb (with file in my main directory), as well as placing it in the data folder and replacing the default argument in style.py with my file name. I get the same error every time. Is there something I am missing when specifying the file?

albertlai commented 7 years ago

The script expects the namespace for the model to be the same as the filename for the .pb file - sorry this was not anywhere in the README! The default model name is "model" so if you didn't specify a name when training, naming the file model.pb ought to work.

I will put up the script I used to export pb files so hopefully that won't be an issue after I clean it up a bit

gaylejj commented 7 years ago

Ahh gotcha. I'll try again in the morning. I had renamed the file, but not to what I specified in the python command.

albertlai commented 7 years ago

OK let me know if it works!

gaylejj commented 7 years ago

So that worked for finding the Tensor, but now I'm getting a new error, which looks like a matrix error.

snip2

albertlai commented 7 years ago

The styling script expects a tensor of shape 1 x image_height x image_width x 3 but the training script has a shape batch_size x image_height x image_width x 3 - when you freeze the pb file you'll have to make sure when you load the StyleTransfer model you set the batch size to 1 so something like

train_model = style_transfer.StyleTransfer( is_training=False, batch_size=1, image_h=args.image_h, image_w=args.image_w, model=args.generator)

gaylejj commented 7 years ago

Ok, I think I understand. So when I set the training, with train.py I need to specify the batch-size of 1?

gaylejj commented 7 years ago

Alright, getting closer...

Now running the command python style.py --model_file=./diving.pb --input=./puppy.jpg --output=./puppy_diving.jpg after training with python train.py --data_dir=./val2014 --texture=diving.jpg --model_name=diving --batch_size=1, I get the following

snip3

Thanks again for all your help, this is a super cool project!

albertlai commented 7 years ago

I uploaded my export script - can you try it out? You run it with

python export.py input_dir=your-models-path

and it outputs a .pb file in that path