Пример #1
0
 def push_1epoch(self):
     print('==> Epoch:[{0}/{1}][pushing stage]'.format(
         self.epoch, self.args.num_epochs))
     push.push_prototypes(
         self.device,
         self.
         push_loader,  # pytorch dataloader (must be unnormalized in [0,1])
         prototype_network_parallel=self.
         model,  # pytorch network with prototype_vectors
         class_specific=True,
         preprocess_input_function=None,  # normalize if needed
         prototype_layer_stride=1,
         epoch_number=self.
         epoch,  # if not provided, prototypes saved previously will be overwritten
         root_dir_for_saving_prototypes=os.path.join(
             self.log_dir, 'prototypes'),
         prototype_img_filename_prefix='prototype_',
         prototype_self_act_filename_prefix='prototype_act_',
         proto_bound_boxes_filename_prefix='prototype_bb_',
         save_prototype_class_identity=True)
Пример #2
0
                  step=step,
                  weighting_attention=args.weighting_attention)
     push_model_state_epoch = None
     if epoch >= config.push_start and epoch in config.push_epochs:
         mode = TrainMode.PUSH
     else:
         epoch += 1
 elif mode == TrainMode.PUSH:
     write_mode(TrainMode.PUSH, log_writer, step)
     push_prototypes(
         train_push_loader,  # pytorch dataloader (must be unnormalized in [0,1])
         prototype_network_parallel=ppnet,
         class_specific=config.class_specific,
         # preprocess_input_function=preprocess_input_function,  # normalize if needed
         prototype_layer_stride=1,
         root_dir_for_saving_prototypes=img_dir,
         epoch_number=epoch,
         prototype_img_filename_prefix=prototype_img_filename_prefix,
         prototype_self_act_filename_prefix=
         prototype_self_act_filename_prefix,
         proto_bound_boxes_filename_prefix=proto_bound_boxes_filename_prefix,
         save_prototype_class_identity=True)
     accu = valid(model=ppnet,
                  dataloader=valid_loader,
                  config=config,
                  log_writer=log_writer,
                  step=step,
                  weighting_attention=args.weighting_attention)
     push_model_state_epoch = epoch
     current_push_best_accu = 0.
     if config.mil_pooling == 'gated_attention' and not ppnet.mil_pooling == 'gated_attention':
Пример #3
0
                                model_dir=model_dir,
                                model_name=str(epoch) + 'nopush',
                                accu=accu,
                                target_accu=0.70,
                                log=log)

    if epoch >= push_start and epoch in push_epochs:
        push.push_prototypes(
            train_push_loader,  # pytorch dataloader (must be unnormalized in [0,1])
            prototype_network_parallel=
            ppnet_multi,  # pytorch network with prototype_vectors
            class_specific=class_specific,
            preprocess_input_function=
            preprocess_input_function,  # normalize if needed
            prototype_layer_stride=1,
            root_dir_for_saving_prototypes=
            img_dir,  # if not None, prototypes will be saved here
            epoch_number=
            epoch,  # if not provided, prototypes saved previously will be overwritten
            prototype_img_filename_prefix=prototype_img_filename_prefix,
            prototype_self_act_filename_prefix=
            prototype_self_act_filename_prefix,
            proto_bound_boxes_filename_prefix=proto_bound_boxes_filename_prefix,
            save_prototype_class_identity=True,
            log=log)
        accu = tnt.test(model=ppnet_multi,
                        dataloader=test_loader,
                        class_specific=class_specific,
                        log=log)
        save.save_model_w_condition(model=ppnet,
                                    model_dir=model_dir,
                                    model_name=str(epoch) + 'push',
Пример #4
0
                      label2name=label2name,
                      optimizer=through_protos_optimizer,
                      args=args,
                      class_specific=class_specific,
                      log=log)

        if epoch > 0 and epoch % args.push_every == 0 or epoch == through_proto_opt - 1:
            push.push_prototypes(
                train_push_loader,  # pytorch dataloader (must be unnormalized in [0,1])
                prototype_network_parallel=
                vgg_multi,  # pytorch network with prototype_vectors
                label2name=label2name,
                class_specific=class_specific,
                preprocess_input_function=
                preprocess_input_function,  # normalize if needed
                prototype_layer_stride=1,
                root_dir_for_saving_prototypes=
                model_dir,  # if not None, prototypes will be saved here
                prototype_img_filename_prefix=prototype_img_filename_prefix,
                prototype_original_img_filename_prefix=
                prototype_original_img_filename_prefix,
                proto_bound_boxes_filename_prefix=
                proto_bound_boxes_filename_prefix,
                save_prototype_class_identity=True,
                log=log)

            acc, _ = tnt.valid(model=vgg_multi,
                               dataloader=valid_loader,
                               label2name=label2name,
                               args=args,
                               class_specific=class_specific,
                               log=log)