SRGAN-tensorflow icon indicating copy to clipboard operation
SRGAN-tensorflow copied to clipboard

Module named "Keras" is not defined

Open nickhdfan opened this issue 7 years ago • 11 comments

I already installed "keras" and used import function in main.py but when I tried to train SRGAN with MSE this happened.

nickhdfan avatar Feb 27 '18 18:02 nickhdfan

@nickhdfan, did you managed to solve this? I'm having the same problem. Supposably only tensorflow was needed.

perdigas91 avatar Mar 08 '18 07:03 perdigas91

Add the following to ops.py import keras

apparently keras is actually a dependency for vgg54 training. If you are planning on training vgg54, you will also have to make the change to the following lines of model.py starting at around line 335. change them to look like this:

if type == 'VGG54':
    target_layer = 'vgg_19/conv5/conv5_4'
elif type == 'VGG22':
    target_layer = 'vgg_19/conv2/conv2_2'

ryancom16 avatar Apr 21 '18 22:04 ryancom16

Hi, I have the same error, and the proposed solution didn't work for me, instead I get this new error:

InvalidArgumentError (see above for traceback): Cannot assign a device for operation 'dicriminator_train/discriminator/discriminator_unit/dense_layer_2/dense/bias/Adam_1': Operation was explicitly assigned to /device:GPU:0 but available devices are [ /job:localhost/replica:0/task:0/device:CPU:0 ]. Make sure the device specification refers to a valid device.
	 [[Node: dicriminator_train/discriminator/discriminator_unit/dense_layer_2/dense/bias/Adam_1 = VariableV2[_class=["loc:@discriminator/discriminator_unit/dense_layer_2/dense/bias"], container="", dtype=DT_FLOAT, shape=[1], shared_name="", _device="/device:GPU:0"]()]]

Someone knows why this happens and how to solve it?

hhsm95 avatar May 03 '18 18:05 hhsm95

i meet the same question, pip install keras, but doesn't work. AttributeError: 'module' object has no attribute 'leaky_relu'

lxk1990727 avatar May 10 '18 04:05 lxk1990727

@adeoy I believe that you have either installed regular tensorflow (not tensorflow-gpu) or you set CUDA_VISIBLE_DEVICES incorrectly when running the training script. Note: pip install tensorflow-gpu is a different from pip install tensorflow

@lxk1990727 Sounds like you need to update your tensorflow.

ryancom16 avatar May 11 '18 20:05 ryancom16

@ryancom16 In fact I installed regular Tensorflow because I dont a GPU on my PC, but my processors are powerful enough to make this tasks. So, I cant do the next training without a GPU? Or how can I solve this problem?

hhsm95 avatar May 12 '18 02:05 hhsm95

Still have the same issue, anyone found a solution?

AdrienLF avatar Jun 02 '18 15:06 AdrienLF

You need to add "import keras" in lib/ops.py

AdrienLF avatar Jun 17 '18 21:06 AdrienLF

I had the same issue during the second step training (SRGAN with MSE loss) and it was solved by adding "import keras" in lib/ops.py

eric-guerin avatar Feb 22 '19 08:02 eric-guerin

yes👍👍" import keras " best solution!!❤❤

rockerritesh avatar Aug 01 '20 08:08 rockerritesh