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

np.shape incompatible error in style_classifier.py #8

Open
juliagong opened this issue Jan 27, 2019 · 14 comments
Open

np.shape incompatible error in style_classifier.py #8

juliagong opened this issue Jan 27, 2019 · 14 comments

Comments

@juliagong
Copy link

juliagong commented Jan 27, 2019

I'm currently using the following command in command prompt on a PC to train the models using the split numpy arrays in ascending order as instructed in the data section of the README: python3 main.py --dataset_A_dir=jazz --dataset_B_dir=classic --type=classifier --model=base --sigma_c=0 --sigma_d=0 --phase=train --which_direction=AtoB

My data is in the np.shape (1, 64, 84, 1), as specified, but the gaussian noise being added is not of the right dimension in style_classifier.py. Is my data in the wrong format? What needs to be changed? Thanks!

@juliagong juliagong changed the title dataset_A_dir and dataset_B_dir np.shape incompatible error in style_classifier.py Jan 27, 2019
@sumuzhao
Copy link
Owner

Hello, Gong. So you want to train the genre classifier? If you want to train cyclegan model, the type should be cyclegan instead of classifier.
I think the shape of added Gaussian noise is the same with data shape. In the style_classifier.py, gaussian_noise = np.random.normal(0, self.sigma_c, [data_test.shape[0], data_test.shape[1], data_test.shape[2], data_test.shape[3]]).
You can send the error traceback here. I'll check it.

@juliagong
Copy link
Author

The error trace when I use cyclegan with the command "python3 main.py --dataset_A_dir=jazz --dataset_B_dir=classic --type=cyclegan --model=base --sigma_c=0 --sigma_d=0 --phase=train --which_direction=AtoB" is:

generatorA2B/g_e1_c/Conv/weights:0
generatorA2B/g_e1_bn/scale:0
generatorA2B/g_e1_bn/offset:0
generatorA2B/g_e2_c/Conv/weights:0
generatorA2B/g_e2_bn/scale:0
generatorA2B/g_e2_bn/offset:0
generatorA2B/g_e3_c/Conv/weights:0
generatorA2B/g_e3_bn/scale:0
generatorA2B/g_e3_bn/offset:0
generatorA2B/g_r1_c1/Conv/weights:0
generatorA2B/g_r1_bn1/scale:0
generatorA2B/g_r1_bn1/offset:0
generatorA2B/g_r1_c2/Conv/weights:0
generatorA2B/g_r1_bn2/scale:0
generatorA2B/g_r1_bn2/offset:0
generatorA2B/g_r2_c1/Conv/weights:0
generatorA2B/g_r2_bn1/scale:0
generatorA2B/g_r2_bn1/offset:0
generatorA2B/g_r2_c2/Conv/weights:0
generatorA2B/g_r2_bn2/scale:0
generatorA2B/g_r2_bn2/offset:0
generatorA2B/g_r3_c1/Conv/weights:0
generatorA2B/g_r3_bn1/scale:0
generatorA2B/g_r3_bn1/offset:0
generatorA2B/g_r3_c2/Conv/weights:0
generatorA2B/g_r3_bn2/scale:0
generatorA2B/g_r3_bn2/offset:0
generatorA2B/g_r4_c1/Conv/weights:0
generatorA2B/g_r4_bn1/scale:0
generatorA2B/g_r4_bn1/offset:0
generatorA2B/g_r4_c2/Conv/weights:0
generatorA2B/g_r4_bn2/scale:0
generatorA2B/g_r4_bn2/offset:0
generatorA2B/g_r5_c1/Conv/weights:0
generatorA2B/g_r5_bn1/scale:0
generatorA2B/g_r5_bn1/offset:0
generatorA2B/g_r5_c2/Conv/weights:0
generatorA2B/g_r5_bn2/scale:0
generatorA2B/g_r5_bn2/offset:0
generatorA2B/g_r6_c1/Conv/weights:0
generatorA2B/g_r6_bn1/scale:0
generatorA2B/g_r6_bn1/offset:0
generatorA2B/g_r6_c2/Conv/weights:0
generatorA2B/g_r6_bn2/scale:0
generatorA2B/g_r6_bn2/offset:0
generatorA2B/g_r7_c1/Conv/weights:0
generatorA2B/g_r7_bn1/scale:0
generatorA2B/g_r7_bn1/offset:0
generatorA2B/g_r7_c2/Conv/weights:0
generatorA2B/g_r7_bn2/scale:0
generatorA2B/g_r7_bn2/offset:0
generatorA2B/g_r8_c1/Conv/weights:0
generatorA2B/g_r8_bn1/scale:0
generatorA2B/g_r8_bn1/offset:0
generatorA2B/g_r8_c2/Conv/weights:0
generatorA2B/g_r8_bn2/scale:0
generatorA2B/g_r8_bn2/offset:0
generatorA2B/g_r9_c1/Conv/weights:0
generatorA2B/g_r9_bn1/scale:0
generatorA2B/g_r9_bn1/offset:0
generatorA2B/g_r9_c2/Conv/weights:0
generatorA2B/g_r9_bn2/scale:0
generatorA2B/g_r9_bn2/offset:0
generatorA2B/g_r10_c1/Conv/weights:0
generatorA2B/g_r10_bn1/scale:0
generatorA2B/g_r10_bn1/offset:0
generatorA2B/g_r10_c2/Conv/weights:0
generatorA2B/g_r10_bn2/scale:0
generatorA2B/g_r10_bn2/offset:0
generatorA2B/g_d1_dc/Conv2d_transpose/weights:0
generatorA2B/g_d1_bn/scale:0
generatorA2B/g_d1_bn/offset:0
generatorA2B/g_d2_dc/Conv2d_transpose/weights:0
generatorA2B/g_d2_bn/scale:0
generatorA2B/g_d2_bn/offset:0
generatorA2B/g_pred_c/Conv/weights:0
generatorB2A/g_e1_c/Conv/weights:0
generatorB2A/g_e1_bn/scale:0
generatorB2A/g_e1_bn/offset:0
generatorB2A/g_e2_c/Conv/weights:0
generatorB2A/g_e2_bn/scale:0
generatorB2A/g_e2_bn/offset:0
generatorB2A/g_e3_c/Conv/weights:0
generatorB2A/g_e3_bn/scale:0
generatorB2A/g_e3_bn/offset:0
generatorB2A/g_r1_c1/Conv/weights:0
generatorB2A/g_r1_bn1/scale:0
generatorB2A/g_r1_bn1/offset:0
generatorB2A/g_r1_c2/Conv/weights:0
generatorB2A/g_r1_bn2/scale:0
generatorB2A/g_r1_bn2/offset:0
generatorB2A/g_r2_c1/Conv/weights:0
generatorB2A/g_r2_bn1/scale:0
generatorB2A/g_r2_bn1/offset:0
generatorB2A/g_r2_c2/Conv/weights:0
generatorB2A/g_r2_bn2/scale:0
generatorB2A/g_r2_bn2/offset:0
generatorB2A/g_r3_c1/Conv/weights:0
generatorB2A/g_r3_bn1/scale:0
generatorB2A/g_r3_bn1/offset:0
generatorB2A/g_r3_c2/Conv/weights:0
generatorB2A/g_r3_bn2/scale:0
generatorB2A/g_r3_bn2/offset:0
generatorB2A/g_r4_c1/Conv/weights:0
generatorB2A/g_r4_bn1/scale:0
generatorB2A/g_r4_bn1/offset:0
generatorB2A/g_r4_c2/Conv/weights:0
generatorB2A/g_r4_bn2/scale:0
generatorB2A/g_r4_bn2/offset:0
generatorB2A/g_r5_c1/Conv/weights:0
generatorB2A/g_r5_bn1/scale:0
generatorB2A/g_r5_bn1/offset:0
generatorB2A/g_r5_c2/Conv/weights:0
generatorB2A/g_r5_bn2/scale:0
generatorB2A/g_r5_bn2/offset:0
generatorB2A/g_r6_c1/Conv/weights:0
generatorB2A/g_r6_bn1/scale:0
generatorB2A/g_r6_bn1/offset:0
generatorB2A/g_r6_c2/Conv/weights:0
generatorB2A/g_r6_bn2/scale:0
generatorB2A/g_r6_bn2/offset:0
generatorB2A/g_r7_c1/Conv/weights:0
generatorB2A/g_r7_bn1/scale:0
generatorB2A/g_r7_bn1/offset:0
generatorB2A/g_r7_c2/Conv/weights:0
generatorB2A/g_r7_bn2/scale:0
generatorB2A/g_r7_bn2/offset:0
generatorB2A/g_r8_c1/Conv/weights:0
generatorB2A/g_r8_bn1/scale:0
generatorB2A/g_r8_bn1/offset:0
generatorB2A/g_r8_c2/Conv/weights:0
generatorB2A/g_r8_bn2/scale:0
generatorB2A/g_r8_bn2/offset:0
generatorB2A/g_r9_c1/Conv/weights:0
generatorB2A/g_r9_bn1/scale:0
generatorB2A/g_r9_bn1/offset:0
generatorB2A/g_r9_c2/Conv/weights:0
generatorB2A/g_r9_bn2/scale:0
generatorB2A/g_r9_bn2/offset:0
generatorB2A/g_r10_c1/Conv/weights:0
generatorB2A/g_r10_bn1/scale:0
generatorB2A/g_r10_bn1/offset:0
generatorB2A/g_r10_c2/Conv/weights:0
generatorB2A/g_r10_bn2/scale:0
generatorB2A/g_r10_bn2/offset:0
generatorB2A/g_d1_dc/Conv2d_transpose/weights:0
generatorB2A/g_d1_bn/scale:0
generatorB2A/g_d1_bn/offset:0
generatorB2A/g_d2_dc/Conv2d_transpose/weights:0
generatorB2A/g_d2_bn/scale:0
generatorB2A/g_d2_bn/offset:0
generatorB2A/g_pred_c/Conv/weights:0
discriminatorB/d_h0_conv/Conv/weights:0
discriminatorB/d_h1_conv/Conv/weights:0
discriminatorB/d_bn1/scale:0
discriminatorB/d_bn1/offset:0
discriminatorB/d_h3_pred/Conv/weights:0
discriminatorA/d_h0_conv/Conv/weights:0
discriminatorA/d_h1_conv/Conv/weights:0
discriminatorA/d_bn1/scale:0
discriminatorA/d_bn1/offset:0
discriminatorA/d_h3_pred/Conv/weights:0

Traceback (most recent call last):
File "main.py", line 73, in
tf.app.run()
File "...\app.py", line 126, in run
_sys.exit(main(argv))
File "main.py", line 65, in main
model.train(args) if args.phase == 'train' else model.test(args)
File "...\model.py", line 246, in train
batch_images = [load_npy_data(batch_file) for batch_file in batch_files]
File "...\model.py", line 246, in
batch_images = [load_npy_data(batch_file) for batch_file in batch_files]
File "...\utils.py", line 101, in load_npy_data
npy_AB = np.concatenate((npy_A.reshape(npy_A.shape[0], npy_A.shape[1], 1),
ValueError: cannot reshape array of size 5376 into shape (1,64,1)

@sumuzhao
Copy link
Owner

I tried by myself and it actually can run.
I checked batch_images = np.array(batch_images).astype(np.float32). The shape of batch_images is (16, 64, 84, 2). I think there might be something wrong about your data sets which are fed as the input. In my case, the shape of each npy file is (1, 64, 84, 1).

PS. I'll upload the data sets which can be used directly.

@juliagong
Copy link
Author

It would be great if you could upload the data sets directly! I checked the shape of each npy file I send in and it's also (1, 64, 84, 1), so I'm not sure that's the issue?

@sumuzhao
Copy link
Owner

Well, it's weird. It should run...
Did you ever change something?

@juliagong
Copy link
Author

I didn't change any of the code, other than adding os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' after os.environ["CUDA_VISIBLE_DEVICES"] = "0". I printed out the shape of batch_files and it's (16, 2), but the line batch_images = [load_npy_data(batch_file) for batch_file in batch_files] causes the error I printed above.

@sumuzhao
Copy link
Owner

I checked the load_npy_data() function in the utlis.py.
The shapes of npy_A, npy_B and npy_AB are as expected: (64, 84, 1), (64, 84, 1), (64, 84, 2).
So I'm also a bit confused why you cannot work. Please wait a moment. I'm preparing my data set. I'll inform you once the data sets are uploaded. Then you can try on my data sets and see how it is.

@juliagong
Copy link
Author

Ah, my npy_A and npy_B shapes are (1, 64, 84, 1). I get the error:
npy_AB = np.concatenate((npy_A.reshape(npy_A.shape[0], npy_A.shape[1], 1),
ValueError: cannot reshape array of size 5376 into shape (1,64,1)

@sumuzhao
Copy link
Owner

I have uploaded the datasets. You can find it in the Dataset part in ReadMe.

@juliagong
Copy link
Author

Thanks! I used your data and there was no error; however, the program ran and there was no additional output other than the initialization of weights, etc. There was an output in the log, but that was it. Where might I find and save the model that I can use to test data on?

@juliagong
Copy link
Author

Hi! I was able to get the code working, but unfortunately, my computer isn't powerful enough to do the training...I was wondering if you'd be willing to upload your weights so I can run the model and see how it works? Thanks a lot!

@sumuzhao
Copy link
Owner

Sorry I don't have time to do this recently due to the final exams. I'll do it later.

@juliagong
Copy link
Author

No worries, I understand! I was wondering if you had any spare time to do it now?

@qedpi
Copy link

qedpi commented Dec 7, 2019

Hi @sumuzhao do you still have the pretrained model weights?

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

3 participants