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

Notebook review #6

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

Conversation

edyoshikun
Copy link

This PR reviews the current img2img translation part 2 (GAN approach) notebook for the DLMBL course.

@edyoshikun edyoshikun marked this pull request as draft August 2, 2024 20:10
@edyoshikun
Copy link
Author

GAN_code/GANs_MI2I/pix2pixHD/options/test_options.py is missing the parse() function. @Tonks684 . Also, there is that tensorboardX dependency that might not be needed. So far that's the extra one I had to pip install.

    def parse(self, args=None):
        if args is None and "ipykernel_launcher" in sys.argv[0]:
            args = []  # Ignore command line arguments in Jupyter
        elif args is None:
            args = sys.argv[1:]

        self.initialize()
        self.opt = self.parser.parse_args(args)
        return self.opt

@edyoshikun
Copy link
Author

Encountering this issue...
EDIT: I had to add opt.isTrain

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
File /home/eduardo.hirata/repos/dlmbl_material/solution.py:14
     [11](https://vscode-remote+ssh-002dremote-002bfry2.vscode-resource.vscode-cdn.net/home/eduardo.hirata/repos/dlmbl_material/solution.py:11) opt.target = "nuclei"  # or "cyto" depending on your choice of target for virtual stain.
     [13](https://vscode-remote+ssh-002dremote-002bfry2.vscode-resource.vscode-cdn.net/home/eduardo.hirata/repos/dlmbl_material/solution.py:13) # Load Training Set for input into model
---> [14](https://vscode-remote+ssh-002dremote-002bfry2.vscode-resource.vscode-cdn.net/home/eduardo.hirata/repos/dlmbl_material/solution.py:14) train_dataloader = CreateDataLoader(opt)
     [15](https://vscode-remote+ssh-002dremote-002bfry2.vscode-resource.vscode-cdn.net/home/eduardo.hirata/repos/dlmbl_material/solution.py:15) opt.isTrain = True
     [17](https://vscode-remote+ssh-002dremote-002bfry2.vscode-resource.vscode-cdn.net/home/eduardo.hirata/repos/dlmbl_material/solution.py:17) dataset_train = train_dataloader.load_data()

File ~/data/06_image_translation/GAN_code/GANs_MI2I/pix2pixHD/data/data_loader_dlmbl.py:6, in CreateDataLoader(opt)
      [4](https://vscode-remote+ssh-002dremote-002bfry2.vscode-resource.vscode-cdn.net/home/eduardo.hirata/repos/dlmbl_material/~/data/06_image_translation/GAN_code/GANs_MI2I/pix2pixHD/data/data_loader_dlmbl.py:4) data_loader = CustomDatasetDataLoader()
      [5](https://vscode-remote+ssh-002dremote-002bfry2.vscode-resource.vscode-cdn.net/home/eduardo.hirata/repos/dlmbl_material/~/data/06_image_translation/GAN_code/GANs_MI2I/pix2pixHD/data/data_loader_dlmbl.py:5) print(data_loader.name())
----> [6](https://vscode-remote+ssh-002dremote-002bfry2.vscode-resource.vscode-cdn.net/home/eduardo.hirata/repos/dlmbl_material/~/data/06_image_translation/GAN_code/GANs_MI2I/pix2pixHD/data/data_loader_dlmbl.py:6) data_loader.initialize(opt)
      [7](https://vscode-remote+ssh-002dremote-002bfry2.vscode-resource.vscode-cdn.net/home/eduardo.hirata/repos/dlmbl_material/~/data/06_image_translation/GAN_code/GANs_MI2I/pix2pixHD/data/data_loader_dlmbl.py:7) return data_loader

File ~/data/06_image_translation/GAN_code/GANs_MI2I/pix2pixHD/data/custom_dataset_data_loader_dlmbl.py:35, in CustomDatasetDataLoader.initialize(self, opt)
     [33](https://vscode-remote+ssh-002dremote-002bfry2.vscode-resource.vscode-cdn.net/home/eduardo.hirata/repos/dlmbl_material/~/data/06_image_translation/GAN_code/GANs_MI2I/pix2pixHD/data/custom_dataset_data_loader_dlmbl.py:33) def initialize(self, opt):
     [34](https://vscode-remote+ssh-002dremote-002bfry2.vscode-resource.vscode-cdn.net/home/eduardo.hirata/repos/dlmbl_material/~/data/06_image_translation/GAN_code/GANs_MI2I/pix2pixHD/data/custom_dataset_data_loader_dlmbl.py:34)     BaseDataLoader.initialize(self, opt)
---> [35](https://vscode-remote+ssh-002dremote-002bfry2.vscode-resource.vscode-cdn.net/home/eduardo.hirata/repos/dlmbl_material/~/data/06_image_translation/GAN_code/GANs_MI2I/pix2pixHD/data/custom_dataset_data_loader_dlmbl.py:35)     self.dataset = CreateDataset(opt)
     [36](https://vscode-remote+ssh-002dremote-002bfry2.vscode-resource.vscode-cdn.net/home/eduardo.hirata/repos/dlmbl_material/~/data/06_image_translation/GAN_code/GANs_MI2I/pix2pixHD/data/custom_dataset_data_loader_dlmbl.py:36)     self.dataloader = torch.utils.data.DataLoader(
     [37](https://vscode-remote+ssh-002dremote-002bfry2.vscode-resource.vscode-cdn.net/home/eduardo.hirata/repos/dlmbl_material/~/data/06_image_translation/GAN_code/GANs_MI2I/pix2pixHD/data/custom_dataset_data_loader_dlmbl.py:37)         self.dataset,
     [38](https://vscode-remote+ssh-002dremote-002bfry2.vscode-resource.vscode-cdn.net/home/eduardo.hirata/repos/dlmbl_material/~/data/06_image_translation/GAN_code/GANs_MI2I/pix2pixHD/data/custom_dataset_data_loader_dlmbl.py:38)         batch_size=opt.batchSize,
     [39](https://vscode-remote+ssh-002dremote-002bfry2.vscode-resource.vscode-cdn.net/home/eduardo.hirata/repos/dlmbl_material/~/data/06_image_translation/GAN_code/GANs_MI2I/pix2pixHD/data/custom_dataset_data_loader_dlmbl.py:39)         shuffle=not opt.serial_batches,
     [40](https://vscode-remote+ssh-002dremote-002bfry2.vscode-resource.vscode-cdn.net/home/eduardo.hirata/repos/dlmbl_material/~/data/06_image_translation/GAN_code/GANs_MI2I/pix2pixHD/data/custom_dataset_data_loader_dlmbl.py:40)         num_workers=int(opt.nThreads))

File ~/data/06_image_translation/GAN_code/GANs_MI2I/pix2pixHD/data/custom_dataset_data_loader_dlmbl.py:21, in CreateDataset(opt)
     [18](https://vscode-remote+ssh-002dremote-002bfry2.vscode-resource.vscode-cdn.net/home/eduardo.hirata/repos/dlmbl_material/~/data/06_image_translation/GAN_code/GANs_MI2I/pix2pixHD/data/custom_dataset_data_loader_dlmbl.py:18) dataset = AlignedDataset()
     [20](https://vscode-remote+ssh-002dremote-002bfry2.vscode-resource.vscode-cdn.net/home/eduardo.hirata/repos/dlmbl_material/~/data/06_image_translation/GAN_code/GANs_MI2I/pix2pixHD/data/custom_dataset_data_loader_dlmbl.py:20) print('dataset [%s] was created' % (dataset.name()))
---> [21](https://vscode-remote+ssh-002dremote-002bfry2.vscode-resource.vscode-cdn.net/home/eduardo.hirata/repos/dlmbl_material/~/data/06_image_translation/GAN_code/GANs_MI2I/pix2pixHD/data/custom_dataset_data_loader_dlmbl.py:21) dataset.initialize(opt)
     [22](https://vscode-remote+ssh-002dremote-002bfry2.vscode-resource.vscode-cdn.net/home/eduardo.hirata/repos/dlmbl_material/~/data/06_image_translation/GAN_code/GANs_MI2I/pix2pixHD/data/custom_dataset_data_loader_dlmbl.py:22) return dataset

File ~/data/06_image_translation/GAN_code/GANs_MI2I/pix2pixHD/data/aligned_dataset_dlmbl.py:27, in AlignedDataset.initialize(self, opt)
     [24](https://vscode-remote+ssh-002dremote-002bfry2.vscode-resource.vscode-cdn.net/home/eduardo.hirata/repos/dlmbl_material/~/data/06_image_translation/GAN_code/GANs_MI2I/pix2pixHD/data/aligned_dataset_dlmbl.py:24) self.A_paths = sorted(make_dataset(self.dir_A))
     [26](https://vscode-remote+ssh-002dremote-002bfry2.vscode-resource.vscode-cdn.net/home/eduardo.hirata/repos/dlmbl_material/~/data/06_image_translation/GAN_code/GANs_MI2I/pix2pixHD/data/aligned_dataset_dlmbl.py:26) ### target B 
---> [27](https://vscode-remote+ssh-002dremote-002bfry2.vscode-resource.vscode-cdn.net/home/eduardo.hirata/repos/dlmbl_material/~/data/06_image_translation/GAN_code/GANs_MI2I/pix2pixHD/data/aligned_dataset_dlmbl.py:27) if opt.isTrain or opt.phase == 'val':         
     [28](https://vscode-remote+ssh-002dremote-002bfry2.vscode-resource.vscode-cdn.net/home/eduardo.hirata/repos/dlmbl_material/~/data/06_image_translation/GAN_code/GANs_MI2I/pix2pixHD/data/aligned_dataset_dlmbl.py:28)     self.dir_B = os.path.join(opt.dataroot,opt.target, f'{opt.phase}')
     [29](https://vscode-remote+ssh-002dremote-002bfry2.vscode-resource.vscode-cdn.net/home/eduardo.hirata/repos/dlmbl_material/~/data/06_image_translation/GAN_code/GANs_MI2I/pix2pixHD/data/aligned_dataset_dlmbl.py:29)     self.B_paths = sorted(make_dataset(self.dir_B))

AttributeError: 'Namespace' object has no attribute 'isTrain'

@edyoshikun
Copy link
Author

edyoshikun commented Aug 2, 2024

I think you need to update https://github.com/Tonks684/GANs_MI2I because I don't have that extra parse() function inside the TestOptions(). I can't run the testing because I get errors running opt = TestOptions().parse(save=False)

@edyoshikun
Copy link
Author

edyoshikun commented Aug 2, 2024

hmm, I now realize that those are part of the base_options.py, so I'm not sure why I am not being able to load them... . Not sure why I am not inheriting the the BaseOptions()

class TrainOptions(BaseOptions):
    def __init__(self):
        super(TrainOptions, self).__init__()
        # Add training-specific arguments here

class TestOptions(BaseOptions):
    def __init__(self):
        super(TestOptions, self).__init__()
        # Add testing-specific arguments here

@edyoshikun
Copy link
Author

Couldn't run the training
train_model( opt, phase2nuclei_model, visualizer, dataset_train, dataset_val, optimizer_G, optimizer_D, start_epoch, epoch_iter, writer, )

{
	"name": "UnboundLocalError",
	"message": "local variable 'train_loss_D_fake' referenced before assignment",
	"stack": "---------------------------------------------------------------------------
UnboundLocalError                         Traceback (most recent call last)
Cell In[11], line 2
      1 # %%
----> 2 train_model(
      3     opt,
      4     phase2nuclei_model,
      5     visualizer,
      6     dataset_train,
      7     dataset_val,
      8     optimizer_G,
      9     optimizer_D,
     10     start_epoch,
     11     epoch_iter,
     12     writer,
     13 )

File ~/data/06_image_translation/GAN_code/GANs_MI2I/pix2pixHD/train_dlmbl.py:341, in train(opt, model, visualizer, dataset_train, dataset_val, optimizer_G, optimizer_D, start_epoch, epoch_iter, writer)
    336     epoch_generator = {\"train\": train_loss_G_Feat, \"validation\": val_loss_G_Feat}
    337     writer.add_scalars(\"Generator Feature Matching Loss\", epoch_generator, epoch)
    339 print(
    340     \"Training Losses: D_fake: {}, D_real: {}, G_GAN: {}, G_GAN_Feat: {}, G_VGG: {}\".format(
--> 341         train_loss_D_fake,
    342         train_loss_D_real,
    343         train_loss_G_GAN,
    344         train_loss_G_Feat,
    345         train_loss_G_VGG,
    346     )
    347 )
    348 print(
    349     \"Validation Losses: D_fake: {}, D_real: {}, G_GAN: {}, G_GAN_Feat: {}, G_VGG: {}\".format(
    350         val_loss_D_fake,
   (...)
    355     )
    356 )
    357 print(
    358     \"End of epoch %d / %d \\t Time Taken: %d sec\"
    359     % (epoch, opt.niter + opt.niter_decay, time.time() - epoch_start_time)
    360 )

UnboundLocalError: local variable 'train_loss_D_fake' referenced before assignment"
}

@Tonks684 Tonks684 marked this pull request as ready for review August 8, 2024 09:58
@Tonks684
Copy link
Owner

Tonks684 commented Aug 9, 2024

Hey Ed,

Commit 9de0694 should now have a working setup.sh.

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

Successfully merging this pull request may close these issues.

2 participants