ml-struct-bio / cryodrgn

Neural networks for cryo-EM reconstruction
http://cryodrgn.cs.princeton.edu
GNU General Public License v3.0
308 stars 76 forks source link

RuntimeError: The size of tensor a (263169) must match the size of tensor b (513) at non-singleton dimension 2 #112

Closed qzj119 closed 2 years ago

qzj119 commented 2 years ago

Hi,Zhong! I ran 256 and 512 graphs in the training process will report such an error, the following is the specific error。 (cryodrgn1) G:\code\cryoDRGN\cryodrgn>cryodrgn train_vae G:/Extract/job069/Micrographs/1002.mrcs --poses pose.pkl --ctf ctf.pkl --zdim 8 -n 50 -o 00_vae512_z8 2022-03-21 11:21:36 D:\Anaconda\envs\cryodrgn1\Scripts\cryodrgn train_vae G:/Extract/job069/Micrographs/1002.mrcs --poses pose.pkl --ctf ctf.pkl --zdim 8 -n 50 -o 00_vae512_z8 2022-03-21 11:21:36 Namespace(particles='G:\Extract\job069\Micrographs\1002.mrcs', outdir='G:\code\cryoDRGN\cryodrgn\00_vae512_z8', zdim=8, poses='G:\cod e\cryoDRGN\cryodrgn\pose.pkl', ctf='G:\code\cryoDRGN\cryodrgn\ctf.pkl', load=None, checkpoint=1, log_interval=1000, verbose=False, seed=66538, invert_data=True , window=True, ind=None, lazy=False, datadir=None, relion31=False, tilt=None, tilt_deg=45, num_epochs=50, batch_size=8, wd=0, lr=0.0001, beta=None, beta_control=None, norm=None, amp=False, multigpu=False, do_pose_sgd=False, pretrain=1, emb_type='quat', pose_lr=0.0003, qlayers=3, qdim=256, encode_mode='resid', enc_mask=None, use_re al=False, players=3, pdim=256, pe_type='geom_lowf', pe_dim=None, domain='fourier', activation='relu', func=<function main at 0x000001F97986E940>) 2022-03-21 11:21:36 Use cuda False 2022-03-21 11:21:36 WARNING: No GPUs detected 2022-03-21 11:21:37 Loaded 1 512x512 images 2022-03-21 11:21:37 Normalized HT by 0 +/- 412.8011474609375 2022-03-21 11:21:37 Loading ctf params from G:\code\cryoDRGN\cryodrgn\ctf.pkl 2022-03-21 11:21:37 Image size (pix) : 512 2022-03-21 11:21:37 A/pix : 0.64453125 2022-03-21 11:21:37 DefocusU (A) : 24457.849609375 2022-03-21 11:21:37 DefocusV (A) : 23901.599609375 2022-03-21 11:21:37 Dfang (deg) : 22.350000381469727 2022-03-21 11:21:37 voltage (kV) : 300.0 2022-03-21 11:21:37 cs (mm) : 0.0 2022-03-21 11:21:37 w : 0.0 2022-03-21 11:21:37 Phase shift (deg) : 0.0 2022-03-21 11:21:37 Using circular lattice with radius 256 2022-03-21 11:21:37 HetOnlyVAE( (encoder): ResidLinearMLP( (main): Sequential( (0): Linear(in_features=205860, out_features=256, bias=True) (1): ReLU() (2): ResidLinear( (linear): Linear(in_features=256, out_features=256, bias=True) ) (3): ReLU() (4): ResidLinear( (linear): Linear(in_features=256, out_features=256, bias=True) ) (5): ReLU() (6): ResidLinear( (linear): Linear(in_features=256, out_features=256, bias=True) ) (7): ReLU() (8): Linear(in_features=256, out_features=16, bias=True) ) ) (decoder): FTPositionalDecoder( (decoder): ResidLinearMLP( (main): Sequential( (0): Linear(in_features=1544, out_features=256, bias=True) (1): ReLU() (2): ResidLinear( (linear): Linear(in_features=256, out_features=256, bias=True) ) (3): ReLU() (4): ResidLinear( (linear): Linear(in_features=256, out_features=256, bias=True) ) (5): ReLU() (6): ResidLinear( (linear): Linear(in_features=256, out_features=256, bias=True) ) (7): ReLU() (8): Linear(in_features=256, out_features=2, bias=True) ) ) ) ) 2022-03-21 11:21:38 53495314 parameters in model 2022-03-21 11:21:38 52901904 parameters in encoder 2022-03-21 11:21:38 593410 parameters in decoder Traceback (most recent call last): File "D:\Anaconda\envs\cryodrgn1\Scripts\cryodrgn-script.py", line 33, in sys.exit(load_entry_point('cryodrgn==0.3.2b0', 'console_scripts', 'cryodrgn')()) File "D:\Anaconda\envs\cryodrgn1\lib\site-packages\cryodrgn-0.3.2b0-py3.9.egg\cryodrgn__main__.py", line 52, in main args.func(args) File "D:\Anaconda\envs\cryodrgn1\lib\site-packages\cryodrgn-0.3.2b0-py3.9.egg\cryodrgn\commands\train_vae.py", line 426, in main loss, gen_loss, kld = train_batch(model, lattice, y, yt, rot, tran, optim, beta, args.beta_control, tilt, ctf_params=ctf_param, yr=yr, use_amp=args.amp) File "D:\Anaconda\envs\cryodrgn1\lib\site-packages\cryodrgn-0.3.2b0-py3.9.egg\cryodrgn\commands\train_vae.py", line 96, in train_batch y, yt = preprocess_input(y, yt, lattice, trans) File "D:\Anaconda\envs\cryodrgn1\lib\site-packages\cryodrgn-0.3.2b0-py3.9.egg\cryodrgn\commands\train_vae.py", line 111, in preprocess_input y = lattice.translate_ht(y.view(B,-1), trans.unsqueeze(1)).view(B,D,D) File "D:\Anaconda\envs\cryodrgn1\lib\site-packages\cryodrgn-0.3.2b0-py3.9.egg\cryodrgn\lattice.py", line 144, in translate_ht return cimg + simg[:,:,np.arange(len(coords)-1,-1,-1)] RuntimeError: The size of tensor a (263169) must match the size of tensor b (513) at non-singleton dimension 2

zhonge commented 2 years ago

Thanks for including the full log. It looks like your input dataset (/Extract/job069/Micrographs/1002.mrcs) only contains a single 512x512 image? You'll want to train on the dataset of extracted particles from the consensus refinement.

qzj119 commented 2 years ago

感谢您提供完整的日志。看起来您的输入数据集 ( /Extract/job069/Micrographs/1002.mrcs) 仅包含一个 512x512 图像?您需要在从共识细化中提取的粒子的数据集上进行训练。

Thanks,I have found the problem. When my MRCS has only one graph, symmetrize_ht(ht) in fft.py changes [1,257,257] to [257,257]. I've changed it and it works fine now