ethereon / lycon

A minimal and fast image library for Python and C++

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot use lycon and TensorFlow in same project

EdeMeijer opened this issue · comments

Hello,

I'm trying to use lycon in a project to rescale images before feeding them into TensorFlow. However, when importing both lycon and TensorFlow in a python application, TensorFlow crashes.

import lycon
import tensorflow as tf

x = tf.placeholder(tf.float32)

Running this code results in the following error

2017-09-10 13:32:53.687783: F tensorflow/core/framework/op.cc:165] Non-OK-status: RegisterAlreadyLocked(deferred_[i]) status: Invalid argument: Could not parse default value '4000' from Attr("upper_frequency_limit: float = 4000") for Op Mfcc
Could not parse default value '20' from Attr("lower_frequency_limit: float = 20") for Op Mfcc

Note I'm not trying to say lycon is at fault here, it might very well be a bug in TensorFlow, but I really don't know where to start. I'm using python 3.5 and the latest version of TensorFlow (1.3.0) and lycon, both installed through pip3. I was hoping you might have a clue what's going on here.

Thanks in advance

These attributes (upper/lower frequency limit) are part of some WIP tensorflow audio operations (tensorflow/tensorflow#11339), so this might be an actual bug, but then I'm wondering why these ops are being loaded when importing lycon, and not when not importing lycon.

I am having the same issue. As a workaround until it gets fixed, you can use lycon, by encapsulating it to functions by importing it only there. For example:

def myFunc():
    # do something
    import lycon
    lycon.someLyconFunction()

You can also create wrapper functions for each of the lycon functions, that will include lycon inside them. But I am afraid that, if your code uses these functions too much, there might be an overhead from the frequent imports.

An example wrapper function for lycon.load():

def load(image_path):
     import lycon
     return lycon.load(image_path)

I am having this issue as well on Python 2.7.

Weird that it works if TensorFlow is imported before Lycon.

import tensorflow as tf
import lycon

x = tf.placeholder(tf.float32)  # works

A better workaround then would be something like:

def myFunc():
    import tensorflow as tf
    import lycon
    # do something with lycon
    lycon.someLyconFunction()

Oddly, I can't seem to reproduce it.

I tested on Ubuntu 14.04 with both Python 2 and 3.
Tensorflow installed using the tensorflow-gpu pip package:

Python 3.5.2 |Anaconda 4.2.0 (64-bit)| (default, Jul  2 2016, 17:53:06)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import lycon
>>> import tensorflow as tf
>>> x = tf.placeholder(tf.float32)
>>> tf.Session().run(tf.reduce_sum(x), feed_dict={x:lycon.load('/tmp/test.png')})
13158753.0
>>> 'Tensorflow version is {}. Lycon version is {}'.format(tf.VERSION, lycon.__version__)
'Tensorflow version is 1.3.0. Lycon version is 0.1.9'

Similarly, no issues on macOS 10.13.
Tensorflow installed using the tensorflow pip package:

Python 3.6.1 |Anaconda 4.4.0 (x86_64)| (default, May 11 2017, 13:04:09)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import lycon
>>> import tensorflow as tf
>>> x = tf.placeholder(tf.float32)
>>> tf.Session().run(tf.reduce_sum(x), feed_dict={x:lycon.load('/tmp/test.png')})
13158753.0
>>> 'Tensorflow version is {}. Lycon version is {}'.format(tf.VERSION, lycon.__version__)
'Tensorflow version is 1.3.0. Lycon version is 0.1.9'

I tried it on another machine with the same result, this time with Tensorflow without GPU support. Both machines are on Ubuntu 16.04, so maybe that's related. I have a 14.04 installation at home, I could try it later today to see if the OS version is the culprit.

Just wanted to add that I ran into an identical error message, except instead of the lycon module it happens to me with the psi4 module. Similarly if tensorflow is imported before psi4 then the issue does not occur. Running Ubuntu 16.04 with python 3.6 from the latest miniconda. Tried with tensorflow installed from conda-forge and from pip with the tfBinaryURL as provided on tensorflow's own website. Seems like this is likely a bug with tensorflow. I'll look around for an issue on the tensorflow github for something similar and if I don't see one I'll open an issue there.