xcssgzs commited on
Commit
547831a
·
verified ·
1 Parent(s): ab6bf95

Upload script.py

Browse files
Files changed (1) hide show
  1. script.py +7 -6
script.py CHANGED
@@ -8,7 +8,7 @@ from torchvision import transforms
8
  from model import resnet101
9
 
10
 
11
- def predict(test_metadata, index2class, root_path='/tmp/data/private_testset', output_csv_path='./submission.csv'):
12
 
13
  data_transform = transforms.Compose(
14
  [transforms.Resize(256),
@@ -17,7 +17,8 @@ def predict(test_metadata, index2class, root_path='/tmp/data/private_testset', o
17
  transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])])
18
 
19
  # load image
20
- img_name_list = ["../tulip.jpg", "../rose.jpg"]
 
21
  id_list = test_metadata['observation_id'].tolist()
22
  img_name_list = test_metadata['filename'].tolist()
23
  img_list = []
@@ -51,7 +52,7 @@ def predict(test_metadata, index2class, root_path='/tmp/data/private_testset', o
51
  id2prob[id] = probs[i]
52
  classes = list()
53
  for id in id_list:
54
- classes.append(index2class[str(id2classId[id])])
55
  test_metadata["class_id"] = classes
56
 
57
  user_pred_df = test_metadata.drop_duplicates("observation_id", keep="first")
@@ -72,8 +73,8 @@ if __name__ == '__main__':
72
  json_path = './class_indices.json'
73
  assert os.path.exists(json_path), "file: '{}' dose not exist.".format(json_path)
74
 
75
- json_file = open(json_path, "r")
76
- index2class = json.load(json_file)
77
 
78
  device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
79
  # create model
@@ -90,4 +91,4 @@ if __name__ == '__main__':
90
  metadata_file_path = "./SnakeCLEF2024_TestMetadata.csv"
91
  # metadata_file_path = "./test.csv"
92
  test_metadata = pd.read_csv(metadata_file_path)
93
- predict(test_metadata, index2class, root_path)
 
8
  from model import resnet101
9
 
10
 
11
+ def predict(test_metadata, root_path='/tmp/data/private_testset', output_csv_path='./submission.csv'):
12
 
13
  data_transform = transforms.Compose(
14
  [transforms.Resize(256),
 
17
  transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])])
18
 
19
  # load image
20
+ # img_name_list = ["1163.jpg", "1164.jpg"]
21
+ # id_list = [1, 2]
22
  id_list = test_metadata['observation_id'].tolist()
23
  img_name_list = test_metadata['filename'].tolist()
24
  img_list = []
 
52
  id2prob[id] = probs[i]
53
  classes = list()
54
  for id in id_list:
55
+ classes.append(str(id2classId[id]))
56
  test_metadata["class_id"] = classes
57
 
58
  user_pred_df = test_metadata.drop_duplicates("observation_id", keep="first")
 
73
  json_path = './class_indices.json'
74
  assert os.path.exists(json_path), "file: '{}' dose not exist.".format(json_path)
75
 
76
+ # json_file = open(json_path, "r")
77
+ # index2class = json.load(json_file)
78
 
79
  device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
80
  # create model
 
91
  metadata_file_path = "./SnakeCLEF2024_TestMetadata.csv"
92
  # metadata_file_path = "./test.csv"
93
  test_metadata = pd.read_csv(metadata_file_path)
94
+ predict(test_metadata, root_path)