lengstrom / fast-style-transfer

TensorFlow CNN for fast style transfer ⚡🖥🎨🖼
10.93k stars 2.6k forks source link

ImportError: cannot import name save_img #196

Closed moldach closed 5 years ago

moldach commented 5 years ago

I'm getting an error from line 7 of the style.py script: from utils import save_img, get_img, exists, list_files

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name save_img

I'f I just import the entire utils module with import utils I'm getting an error for the evaluate module which I have no idea what this is. I cannot find it with pip install evaluate nor are Google searches showing anything about these two errors. I've tried this in separate environments for both python 2.7 and python 3.6 now

moldach commented 5 years ago

One of two things seems to have solved the above problem of loading save_img from utils and evaluate. I was playing around with https://github.com/anishathalye/neural-style as well so it was either from 1) Loading cuda(?), 2) placing imagenet-vgg-verydeep-19.mat in the top directory of fast-style-transfer-master, or 3) pip install -r requirements.txt

However; another problem pops up:

(ENV) [moldach@beluga3 fast-style-transfer-master]$ python style.py --style examples/style/rain_princess.jpg --checkpoint-dir ./ --test examples/content/chicago.jpg  --test-dir test/ --content-weight 1.5e1 --checkpoint-iterations 1000 --batch-size 20
Traceback (most recent call last):
  File "style.py", line 167, in <module>
    main()
  File "style.py", line 115, in main
    check_opts(options)
  File "style.py", line 91, in check_opts
    exists(opts.checkpoint_dir, "checkpoint dir not found!")
NameError: name 'exists' is not defined
lkolbly commented 5 years ago

The evaluate module is evaluate.py, you shouldn't need (or be able to) pip install it.

Likewise, exists is defined in src/utils.py, so as long as you're able to from utils import exists I don't know why you'd be getting that error...

Note that there's some import path trickery going on: src is manually added to the front of sys.path at the top of style.py.

moldach commented 5 years ago

Turns out it was an issue with tensorflow and cuda. Although it's pretty specific to Compute Canada users (I'm on Beluga) here's the script I used to run the transform_video.py script:

#!/bin/bash
#SBATCH --gres=gpu:1        # request GPU "generic resource"
#SBATCH --cpus-per-task=6   # maximum CPU cores per GPU request: 6 on Cedar, 16 on Graham.
#SBATCH --time=0-00:02:00      # time (DD-HH:MM)
#SBATCH --mem=10000
#SBATCH --output=%N-%j.out  # %N for node name, %j for jobID

#module load cuda cudnn
module load python/2.7.14
module load scipy-stack
source tensorflow/bin/activate

python transform_video.py --in-path flip.mp4 --checkpoint wave.ckpt --out-path wave-flip.mp4 --batch-size 4