Search code examples
pycharmanaconda

What is"error: the following arguments are required"?


When Iam running a github project(ID-disentanglement) in Anaconda IDE, I am getting an error like this, can you explain how to resolve this error?

Using TensorFlow backend.
usage: main.py [-h] [--gpu GPU] [--face_detection] [--resolution {256,1024}]
               [--load_checkpoint LOAD_CHECKPOINT] --pretrained_models_path
               PRETRAINED_MODELS_PATH [--const_noise | --no_const_noise]
               [--batch_size BATCH_SIZE] [--reals]
               [--test_real_attr | --no_test_real_attr]
               [--results_dir RESULTS_DIR] [--log_debug] [--debug]
               [--dataset_path DATASET_PATH] [--num_epochs NUM_EPOCHS]
               [--cross_frequency CROSS_FREQUENCY] [--unified]
               [--train_real_attr | --no_train_real_attr]
               [--train_data_size TRAIN_DATA_SIZE] [--id_loss | --no_id_loss]
               [--landmarks_loss | --no_landmarks_loss]
               [--pixel_loss | --no_pixel_loss] [--W_D_loss | --no_W_D_loss]
               [--gp | --no_gp] [--pixel_mask_type {uniform,gaussian}]
               [--pixel_loss_type {L1,mix}] [--test_frequency TEST_FREQUENCY]
               [--test_size TEST_SIZE] [--not_improved_exit NOT_IMPROVED_EXIT]
               [--test_with_arcface | --no_test_with_arcface]
               name
main.py: error: the following arguments are required: name

arglib.py is imported in main.py, so I think the problem may come from arglib.py. And there is a class from arglib.py and its function that I think which cause this problem(my assumption may not be right).

    class BaseArgs(ABC):
        @abstractmethod
        def add_args(self):
            # Hardware
            self.parser.add_argument('--gpu', type=str, default='0')
    
            # Model
            self.parser.add_argument('--face_detection', action='store_true')
            self.parser.add_argument('--resolution', type=int, default=256, choices=[256, 1024])
            self.parser.add_argument('--load_checkpoint')
            self.parser.add_argument('--pretrained_models_path', type=Path, required=True)

            BaseArgs.add_bool_arg(self.parser, 'const_noise')

            # Data
            self.parser.add_argument('--batch_size', type=int, default=6)
            self.parser.add_argument('--reals', action='store_true', help='Use real inputs')
            BaseArgs.add_bool_arg(self.parser, 'test_real_attr')

            # Log & Results
            self.parser.add_argument('name', type=str, help='Name under which run will be saved')
            self.parser.add_argument('--results_dir', type=str, default='../results')
            self.parser.add_argument('--log_debug', action='store_true')
    
            # Other
            self.parser.add_argument('--debug', action='store_true')

And I asked chatGPT, and it said "name: Requires the user to provide a name under which the run will be saved. For example, my_experiment_name." I also searched for solution, they said I should add name in "Run/Debug configuration". I've tried this name(my_experiment_name), as well as other names like the file's name or folder's name, but no matter what, it always result in an error:"main.py: error: unrecognized arguments:". My question is, should I try a different name? Or is the problem not really about the name at all?

And there is the picture of how I set up my parameters


Solution

  • Generally, when using the argparse.ArgumentParser(), errors or help-information will be displayed in the format you wrote:

    usage: main.py [-h] [--gpu GPU] [--face_detection] [--resolution {256,1024}]
                   [--load_checkpoint LOAD_CHECKPOINT] --pretrained_models_path
                   PRETRAINED_MODELS_PATH [--const_noise | --no_const_noise]
                   [--batch_size BATCH_SIZE] [--reals]
                   [--test_real_attr | --no_test_real_attr]
                   [--results_dir RESULTS_DIR] [--log_debug] [--debug]
                   [--dataset_path DATASET_PATH] [--num_epochs NUM_EPOCHS]
                   [--cross_frequency CROSS_FREQUENCY] [--unified]
                   [--train_real_attr | --no_train_real_attr]
                   [--train_data_size TRAIN_DATA_SIZE] [--id_loss | --no_id_loss]
                   [--landmarks_loss | --no_landmarks_loss]
                   [--pixel_loss | --no_pixel_loss] [--W_D_loss | --no_W_D_loss]
                   [--gp | --no_gp] [--pixel_mask_type {uniform,gaussian}]
                   [--pixel_loss_type {L1,mix}] [--test_frequency TEST_FREQUENCY]
                   [--test_size TEST_SIZE] [--not_improved_exit NOT_IMPROVED_EXIT]
                   [--test_with_arcface | --no_test_with_arcface]
                   name
    

    What this shows, is that running the script should be done as:

    python main.py [optional arguments here] name
    
    e.g.
    python main.py my_special_name
    python main.py --batch_size 25 my_special_name
    python main.py --batch_size 25 --reals my_special_name
    ...
    

    Most IDE's allows you to set up a run or debug configuration, for which script to run and which arguments to pass.

    argparse.ArgumentParser() is an easy to use built-in class for managing arguments in Python - you could also just use sys.argv directly, which will contain a list of arguments passed to the program.