Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to solve this error. #2

Open
firestonelib opened this issue Apr 21, 2017 · 18 comments
Open

how to solve this error. #2

firestonelib opened this issue Apr 21, 2017 · 18 comments

Comments

@firestonelib
Copy link

Dear sir,
when I run : python train.py --path /mnt/data1/GAN/heart --batch_size 8 --epochs 8 --TYPE train
it return error: I wanna why this happened.
Traceback (most recent call last):
File "train.py", line 196, in
train(path = args.path, batch_size = args.batch_size, EPOCHS = args.epochs)
File "train.py", line 64, in train
discriminator_on_generator = model.generator_containing_discriminator(generator, discriminator)
File "/mnt/data1/daniel/codes/GAN/GAN/model.py", line 102, in generator_containing_discriminator
model.add(discriminator)
File "/mnt/data1/daniel/Python-2.7.13/build/lib/python2.7/site-packages/keras/models.py", line 463, in add
output_tensor = layer(self.outputs[0])
File "/mnt/data1/daniel/Python-2.7.13/build/lib/python2.7/site-packages/keras/engine/topology.py", line 578, in call
output = self.call(inputs, **kwargs)
File "/mnt/data1/daniel/Python-2.7.13/build/lib/python2.7/site-packages/keras/models.py", line 520, in call
return self.model.call(inputs, mask)
File "/mnt/data1/daniel/Python-2.7.13/build/lib/python2.7/site-packages/keras/engine/topology.py", line 1989, in call
output_tensors, _, _ = self.run_internal_graph(inputs, masks)
File "/mnt/data1/daniel/Python-2.7.13/build/lib/python2.7/site-packages/keras/engine/topology.py", line 2140, in run_internal_graph
output_tensors = _to_list(layer.call(computed_tensor, **kwargs))
File "/mnt/data1/daniel/Python-2.7.13/build/lib/python2.7/site-packages/keras/layers/convolutional.py", line 164, in call
dilation_rate=self.dilation_rate)
File "/mnt/data1/daniel/Python-2.7.13/build/lib/python2.7/site-packages/keras/backend/tensorflow_backend.py", line 2893, in conv2d
data_format='NHWC')
File "/mnt/data1/daniel/tensorflow/_python_build/tensorflow/python/ops/nn_ops.py", line 650, in convolution
num_spatial_dims]))
ValueError: number of input channels does not match corresponding dimension of filter, 3 != 64

@w007878
Copy link

w007878 commented May 8, 2017

I got this error too

@jhayes14
Copy link
Owner

jhayes14 commented May 8, 2017

Probably a channel ordering mismatch in your keras backend. https://keras.io/backend/

@w007878
Copy link

w007878 commented May 8, 2017

I change my backend into theano, but I got another error message
Traceback (most recent call last):
File "train.py", line 196, in
train(path = args.path, batch_size = args.batch_size, EPOCHS = args.epochs)
File "train.py", line 64, in train
discriminator_on_generator = model.generator_containing_discriminator(generator, discriminator)
File "/home/w007878/workspace/GAN/model.py", line 102, in generator_containing_discriminator
model.add(discriminator)
File "/usr/local/lib/python2.7/dist-packages/keras/models.py", line 332, in add
output_tensor = layer(self.outputs[0])
File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 572, in call
self.add_inbound_node(inbound_layers, node_indices, tensor_indices)
File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 635, in add_inbound_node
Node.create_node(self, inbound_layers, node_indices, tensor_indices)
File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 166, in create_node
output_tensors = to_list(outbound_layer.call(input_tensors[0], mask=input_masks[0]))
File "/usr/local/lib/python2.7/dist-packages/keras/models.py", line 386, in call
return self.model.call(x, mask)
File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 2247, in call
output_tensors, output_masks, output_shapes = self.run_internal_graph(inputs, masks)
File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 2420, in run_internal_graph
shapes = to_list(layer.get_output_shape_for(computed_tensors[0]._keras_shape))
File "/usr/local/lib/python2.7/dist-packages/keras/layers/core.py", line 821, in get_output_shape_for
assert input_shape[-1] and input_shape[-1] == self.input_dim
AssertionError

@w007878
Copy link

w007878 commented May 9, 2017

Alright, I have fixed this one.
Here is my keras.json

{
    "image_dim_ordering": "th", 
    "epsilon": 1e-07, 
    "floatx": "float32", 
    "backend": "theano"
}

It may help

@firestonelib
Copy link
Author

Hi, thank you @w007878 ,but where is the keras.json?

@w007878
Copy link

w007878 commented May 9, 2017

@Designbook1 It is under your home directory ~/.keras
If you cannot find it, just create one.
To change the backend, you must have theano installed.
I hope it can work to you 😄

@firestonelib
Copy link
Author

@w007878 when I fixed the keras.json, it errors:

Traceback (most recent call last):
  File "train.py", line 6, in <module>
    import model
  File "/mnt/data1/daniel/codes/GAN/GAN/model.py", line 1, in <module>
    from keras.models import Sequential, Model
  File "/mnt/data1/daniel/Python-2.7.13/build/lib/python2.7/site-packages/keras/__init__.py", line 3, in <module>
    from . import activations
  File "/mnt/data1/daniel/Python-2.7.13/build/lib/python2.7/site-packages/keras/activations.py", line 3, in <module>
    from . import backend as K
  File "/mnt/data1/daniel/Python-2.7.13/build/lib/python2.7/site-packages/keras/backend/__init__.py", line 70, in <module>
    from .theano_backend import *
  File "/mnt/data1/daniel/Python-2.7.13/build/lib/python2.7/site-packages/keras/backend/theano_backend.py", line 3, in <module>
    import theano
  File "/mnt/data1/daniel/Python-2.7.13/build/lib/python2.7/site-packages/theano/__init__.py", line 66, in <module>
    from theano.compile import (
  File "/mnt/data1/daniel/Python-2.7.13/build/lib/python2.7/site-packages/theano/compile/__init__.py", line 10, in <module>
    from theano.compile.function_module import *
  File "/mnt/data1/daniel/Python-2.7.13/build/lib/python2.7/site-packages/theano/compile/function_module.py", line 21, in <module>
    import theano.compile.mode
  File "/mnt/data1/daniel/Python-2.7.13/build/lib/python2.7/site-packages/theano/compile/mode.py", line 10, in <module>
    import theano.gof.vm
  File "/mnt/data1/daniel/Python-2.7.13/build/lib/python2.7/site-packages/theano/gof/vm.py", line 662, in <module>
    from . import lazylinker_c
  File "/mnt/data1/daniel/Python-2.7.13/build/lib/python2.7/site-packages/theano/gof/lazylinker_c.py", line 127, in <module>
    preargs=args)
  File "/mnt/data1/daniel/Python-2.7.13/build/lib/python2.7/site-packages/theano/gof/cmodule.py", line 2316, in compile_str
    (status, compile_stderr.replace('\n', '. ')))
Exception: Compilation failed (return status=1): /usr/bin/ld: /mnt/data1/daniel/Python-2.7.13/build/lib/libpython2.7.a(abstract.o): relocation R_X86_64_32S against `_Py_NotImplementedStruct' can not be used when making a shared object; recompile with -fPIC. /mnt/data1/daniel/Python-2.7.13/build/lib/libpython2.7.a: could not read symbols: wrong value. collect2: Error:ld return 1. 

@w007878
Copy link

w007878 commented May 9, 2017

@Designbook1 I think there may be something wrong with your theano installation, how about try to reinstall it ?

@einarkurbitur
Copy link

I keep getting an error too
I type in : python2 train.py --path /test --TYPE 'train' --batch_size 10 --epochs 10

and get:
Using Theano backend.
Loading paths..
Got paths..
Number of batches 0
Batch size is 10

Epoch 0

Traceback (most recent call last):
File "train.py", line 196, in
train(path = args.path, batch_size = args.batch_size, EPOCHS = args.epochs)
File "train.py", line 153, in train
for i, img in enumerate(generated_images[:5]):
UnboundLocalError: local variable 'generated_images' referenced before assignment

Am I doing something wrong or do I have wrong libraries installed?

@jhayes14
Copy link
Owner

The number of batches in your code is zero. This means lines 96-152 won't be executed and so generated_images won't be assigned resulting in the error. How many images are in your path?

@einarkurbitur
Copy link

einarkurbitur commented Oct 29, 2017

I have 11 .jpg images in my path now

tree view over my directory
├── [ 3353] 7.jpg
├── [ 2642] Epoch_13_example.jpg
├── [ 4697] README.md
├── [ 5458] TEST.jpg
├── [ 4191] model.py
├── [ 4499] model.pyc
├── [ 5062] model_tests.py
├── [ 476] test
│   ├── [ 3389] boxy_stripes2.jpg
│   ├── [ 3089] boxy_stripes2_120.jpg
│   ├── [ 3582] boxy_stripes2_150.jpg
│   ├── [ 3402] boxy_stripes2_180.jpg
│   ├── [ 3071] boxy_stripes2_210.jpg
│   ├── [ 3601] boxy_stripes2_240.jpg
│   ├── [ 3435] boxy_stripes2_270.jpg
│   ├── [ 3065] boxy_stripes2_30.jpg
│   ├── [ 3101] boxy_stripes2_300.jpg
│   ├── [ 3625] boxy_stripes2_60.jpg
│   └── [ 3379] boxy_stripes2_90.jpg
└── [ 7291] train.py

@jhayes14
Copy link
Owner

Can you confirm the images are being loaded? Line 52

@einarkurbitur
Copy link

Yes now they seem to be loading (changed) my path but then I get another error.

python2 train.py --path test --TYPE 'train' --batch_size 1 --epochs 2
Using Theano backend.
Loading paths..
Got paths..
printing paths
[[[[ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   ...,
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]]

  [[ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   ...,
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]]

  [[ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   ...,
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]]]


 [[[ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   ...,
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]]

  [[ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   ...,
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]]

  [[ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   ...,
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]]]


 [[[ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   ...,
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]]

  [[ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   ...,
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]]

  [[ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   ...,
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]]]


 ...,
 [[[ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   ...,
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]]

  [[ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   ...,
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]]

  [[ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   ...,
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]]]


 [[[ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   ...,
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]]

  [[ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   ...,
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]]

  [[ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   ...,
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]]]


 [[[ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   ...,
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]]

  [[ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   ...,
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]]

  [[ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   ...,
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]
   [ 1.  1.  1. ...,  1.  1.  1.]]]]
end path printing
/Users/einar/Desktop/GDA_Y3/ResearchLab/7/GAN/model.py:48: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(128, (5, 5), padding="same", strides=(2, 2), input_shape=(3, 64, 64...)`
  model.add(Convolution2D(128, 5, 5, subsample=(2, 2), input_shape=(3, 64, 64), border_mode = 'same'))
/Users/einar/Desktop/GDA_Y3/ResearchLab/7/GAN/model.py:51: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(256, (5, 5), padding="same", strides=(2, 2))`
  model.add(Convolution2D(256, 5, 5, subsample=(2, 2), border_mode = 'same'))
/Users/einar/Desktop/GDA_Y3/ResearchLab/7/GAN/model.py:54: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(512, (5, 5), padding="same", strides=(2, 2))`
  model.add(Convolution2D(512, 5, 5, subsample=(2, 2), border_mode = 'same'))
/Users/einar/Desktop/GDA_Y3/ResearchLab/7/GAN/model.py:57: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(1024, (5, 5), padding="same", strides=(2, 2))`
  model.add(Convolution2D(1024, 5, 5, subsample=(2, 2), border_mode = 'same'))
/Users/einar/Desktop/GDA_Y3/ResearchLab/7/GAN/model.py:61: UserWarning: Update your `Dense` call to the Keras 2 API: `Dense(units=1)`
  model.add(Dense(output_dim=1))
/Users/einar/Desktop/GDA_Y3/ResearchLab/7/GAN/model.py:25: UserWarning: Update your `Dense` call to the Keras 2 API: `Dense(units=16384, input_dim=100)`
  model.add(Dense(input_dim=inputdim, output_dim=1024*xdim*ydim))
/Users/einar/Desktop/GDA_Y3/ResearchLab/7/GAN/model.py:30: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(512, (5, 5), padding="same")`
  model.add(Convolution2D(512, 5, 5, border_mode='same'))
/Users/einar/Desktop/GDA_Y3/ResearchLab/7/GAN/model.py:34: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(256, (5, 5), padding="same")`
  model.add(Convolution2D(256, 5, 5, border_mode='same'))
/Users/einar/Desktop/GDA_Y3/ResearchLab/7/GAN/model.py:38: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(128, (5, 5), padding="same")`
  model.add(Convolution2D(128, 5, 5, border_mode='same'))
/Users/einar/Desktop/GDA_Y3/ResearchLab/7/GAN/model.py:42: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(3, (5, 5), padding="same")`
  model.add(Convolution2D(3, 5, 5, border_mode='same'))
Number of batches 11
Batch size is 1

Epoch 0

Epoch 0 Batch 0
Traceback (most recent call last):
  File "train.py", line 198, in <module>
    train(path = args.path, batch_size = args.batch_size, EPOCHS = args.epochs)
  File "train.py", line 109, in train
    Xd = np.concatenate((image_batch, generated_images))
ValueError: all the input array dimensions except for the concatenation axis must match exactly

@sevazhidkov
Copy link

sevazhidkov commented Nov 26, 2017

You don't need to use Theano backend for it. Here is my keras.json:

{
    "floatx": "float32",
    "epsilon": 1e-07,
    "backend": "tensorflow",
    "image_data_format": "channels_first"
}

The only difference between original Keras configuration is image data format convention: by default "image_data_format" is "channels_last".

@innarid
Copy link

innarid commented Feb 10, 2018

@einarkurbitur did you find the solution to your problem?
"ValueError: all the input array dimensions except for the concatenation axis must match exactly"

@einarkurbitur
Copy link

@innarid
No sorry I just gave up eventually if I remember correctly.

@innarid
Copy link

innarid commented Feb 11, 2018

@einarkurbitur thanks all the same)

@TonyAssi
Copy link

@sevazhidkov solution worked for me
cd ~/.keras/
sudo nano keras.json
{
"backend": "tensorflow",
"epsilon": 1e-07,
"floatx": "float32",
"image_data_format": "channels_first"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants