CycleGAN-Music-Style-Transfer icon indicating copy to clipboard operation
CycleGAN-Music-Style-Transfer copied to clipboard

np.shape incompatible error in style_classifier.py

Open juliagong opened this issue 5 years ago • 14 comments

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 avatar Jan 27 '19 01:01 juliagong

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.

sumuzhao avatar Jan 27 '19 08:01 sumuzhao

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)

juliagong avatar Jan 27 '19 17:01 juliagong

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.

sumuzhao avatar Jan 27 '19 18:01 sumuzhao

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?

juliagong avatar Jan 27 '19 18:01 juliagong

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

sumuzhao avatar Jan 27 '19 18:01 sumuzhao

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.

juliagong avatar Jan 27 '19 18:01 juliagong

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.

sumuzhao avatar Jan 27 '19 18:01 sumuzhao

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)

juliagong avatar Jan 27 '19 18:01 juliagong

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

sumuzhao avatar Jan 27 '19 19:01 sumuzhao

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 avatar Jan 27 '19 22:01 juliagong

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!

juliagong avatar Jan 28 '19 05:01 juliagong

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

sumuzhao avatar Jan 29 '19 06:01 sumuzhao

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

juliagong avatar Feb 12 '19 00:02 juliagong

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

qedpi avatar Dec 07 '19 04:12 qedpi