bupt-ai-cz / BCI

BCI: Breast Cancer Immunohistochemical Image Generation through Pyramid Pix2pix
Other
184 stars 18 forks source link

如何进行测试呢? #5

Open xiaoerjason opened 1 year ago

xiaoerjason commented 1 year ago

当我使用预训练模型进行推理的时候发生了错误: torch.nn.modules.module.ModuleAttributeError: 'Sequential' object has no attribute 'model'

xiaoerjason commented 1 year ago

----------------- Options --------------- aspect_ratio: 1.0
batch_size: 2
checkpoints_dir: ./checkpoints
crop_size: 256
dataroot: ./test_img [default: ./datasets/BCI] dataset_mode: aligned
direction: AtoB
display_winsize: 256
epoch: latest
eval: False
gpu_ids: 0
init_gain: 0.02
init_type: normal
input_nc: 3
isTrain: False [default: None] load_iter: 0 [default: 0] load_size: 320
max_dataset_size: inf
model: pix2pix
n_layers_D: 3
name: pyramidpix2pix
ndf: 64
netD: basic
netG: resnet_9blocks
ngf: 64
no_dropout: False
no_flip: False
norm: batch
num_test: 1000
num_threads: 4
output_nc: 3
pattern: L1_L2_L3_L4
phase: test
preprocess: scale_width_and_midcrop
results_dir: ./results/
serial_batches: False
suffix:
verbose: False
----------------- End -------------------

SantJay commented 1 year ago

这可能是pytorch版本和模型不匹配造成的。我们使用的pytorch版本为1.9.0,您可以使用和我们一样的版本测试一下。

arshamhaq commented 8 months ago

@xiaoerjason , @SantJay hello I have the exact same problem I am using PyTorch 1.9.0 but the error is exactly the same! I have tried everything but I can't generate images using pre-trained model here is the exact issue: ----------------- Options --------------- aspect_ratio: 1.0 batch_size: 2 checkpoints_dir: ./checkpoints crop_size: 256 dataroot: ./datasets/BCI dataset_mode: aligned direction: AtoB display_winsize: 256 epoch: latest eval: False gpu_ids: -1 init_gain: 0.02 init_type: normal input_nc: 3 isTrain: False [default: None] load_iter: 0 [default: 0] load_size: 320 max_dataset_size: inf model: pix2pix n_layers_D: 3 name: pyramidpix2pix ndf: 64 netD: basic netG: resnet_9blocks ngf: 64 no_dropout: False no_flip: False norm: batch num_test: 1000 num_threads: 4 output_nc: 3 pattern: L1_L2_L3_L4 phase: test preprocess: scale_width_and_midcrop results_dir: ./results/ serial_batches: False suffix: verbose: False ----------------- End ------------------- dataset [AlignedDataset] was created initialize network with normal model [Pix2PixModel] was created loading the model from ./checkpoints\pyramidpix2pix\latest_net_G.pth Traceback (most recent call last): File "test.py", line 47, in model.setup(opt) # regular setup: load and print networks; create schedulers File .\base_model.py", line 88, in setup self.load_networks(load_suffix) File ".\base_model.py", line 198, in load_networks self.patch_instance_norm_state_dict(state_dict, net, key.split('.')) File ".\base_model.py", line 174, in patch_instance_norm_state_dict self.patch_instance_norm_state_dict(state_dict, getattr(module, key), keys, i + 1) File ".\base_model.py", line 174, in patch_instance_norm_state_dict self.__patch_instance_norm_state_dict(state_dict, getattr(module, key), keys, i + 1) File ".\torch\nn\modules\module.py", line 1130, in getattr raise AttributeError("'{}' object has no attribute '{}'".format( AttributeError: 'Sequential' object has no attribute 'model'

ittong commented 4 months ago

@arsham-khafan , @SantJay ,@xiaoerjason, @bupt-ai-cz Can you set the netG parameter in base_options to "attention_unet_32"? The weights file provided by the author is actually for "attention_unet_32", not "resnet_9blocks".

arshamhaq commented 4 months ago

@ittong Genius! it worked, thank you so much @SantJay please update the read me file and note that the netG must be "attention_unet_32"