arser = argparse.ArgumentParser(description="Run GHCN.") parser.add_argument('--data_path', type=str, default='./data/', help='Input data path') parser.add_argument('--model_path', type=str, default='checkpoint.pt', help='Saved model path.') parser.add_argument('--dataset', type=str, default='Cora', help='Choose a dataset from {Cora, CiteSeer, PubMed}') parser.add_argument('--split', type=str, default='full', help='The type of dataset split {public, full, random}') parser.add_argument('--trim_prob', type=float, default=0.2, help='The probability to trim adj, 0 not trim, 1 trim') parser.add_argument('--seed', type=int, default=123, help='Random seed') parser.add_argument('--epoch', type=int, default=1000, help='Number of epochs to train') parser.add_argument('--lr', type=float, default=0.005, help='Initial learning rate') parser.add_argument('--weight_decay', type=float, default=5e-4, help='Weight decay (L2 norm on parameters)') parser.add_argument('--k', type=int, default=10, help='k-hop aggregation') parser.add_argument('--hidden', type=int, default=64, help='Number of hidden units') parser.add_argument('--dropout', type=float, default=0.7, help='Dropout rate') parser.add_argument('--patience', type=int, default=100, help='How long to wait after last time validation improved') args = parser.parse_args() for arg in vars(args): print('{0} = {1}'.format(arg, getattr(args, arg))) 修改代码要求:如果dataset不等于{Cora, CiteSeer, PubMed}中的任何一项则不打印split
时间: 2023-11-28 22:04:40 浏览: 115
修改后的代码如下:
```python
import argparse
parser = argparse.ArgumentParser(description="Run GHCN.")
parser.add_argument('--data_path', type=str, default='./data/', help='Input data path')
parser.add_argument('--model_path', type=str, default='checkpoint.pt', help='Saved model path.')
parser.add_argument('--dataset', type=str, default='Cora', help='Choose a dataset from {Cora, CiteSeer, PubMed}')
parser.add_argument('--split', type=str, default='full', help='The type of dataset split {public, full, random}')
parser.add_argument('--trim_prob', type=float, default=0.2, help='The probability to trim adj, 0 not trim, 1 trim')
parser.add_argument('--seed', type=int, default=123, help='Random seed')
parser.add_argument('--epoch', type=int, default=1000, help='Number of epochs to train')
parser.add_argument('--lr', type=float, default=0.005, help='Initial learning rate')
parser.add_argument('--weight_decay', type=float, default=5e-4, help='Weight decay (L2 norm on parameters)')
parser.add_argument('--k', type=int, default=10, help='k-hop aggregation')
parser.add_argument('--hidden', type=int, default=64, help='Number of hidden units')
parser.add_argument('--dropout', type=float, default=0.7, help='Dropout rate')
parser.add_argument('--patience', type=int, default=100, help='How long to wait after last time validation improved')
args = parser.parse_args()
if args.dataset in {'Cora', 'CiteSeer', 'PubMed'}:
for arg in vars(args):
print('{0} = {1}'.format(arg, getattr(args, arg)))
else:
print("Invalid dataset! Valid options are {Cora, CiteSeer, PubMed}.")
```
如果输入的 dataset 不是 {Cora, CiteSeer, PubMed} 中的任何一项,将会输出 "Invalid dataset! Valid options are {Cora, CiteSeer, PubMed}.",否则将会输出各个参数的值。
阅读全文