Skip to content

Commit b9ecb17

Browse files
committedApr 6, 2022
update read json file code
1 parent 2341f05 commit b9ecb17

File tree

24 files changed

+48
-48
lines changed

24 files changed

+48
-48
lines changed
 

‎pytorch_classification/ConvNeXt/predict.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ def main():
3535
json_path = './class_indices.json'
3636
assert os.path.exists(json_path), "file: '{}' dose not exist.".format(json_path)
3737

38-
json_file = open(json_path, "r")
39-
class_indict = json.load(json_file)
38+
with open(json_path, "r") as f:
39+
class_indict = json.load(f)
4040

4141
# create model
4242
model = create_model(num_classes=num_classes).to(device)

‎pytorch_classification/Test10_regnet/predict.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ def main():
3232
json_path = './class_indices.json'
3333
assert os.path.exists(json_path), "file: '{}' dose not exist.".format(json_path)
3434

35-
json_file = open(json_path, "r")
36-
class_indict = json.load(json_file)
35+
with open(json_path, "r") as f:
36+
class_indict = json.load(f)
3737

3838
# create model
3939
model = create_regnet(model_name="RegNetY_400MF", num_classes=5).to(device)

‎pytorch_classification/Test11_efficientnetV2/predict.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ def main():
3737
json_path = './class_indices.json'
3838
assert os.path.exists(json_path), "file: '{}' dose not exist.".format(json_path)
3939

40-
json_file = open(json_path, "r")
41-
class_indict = json.load(json_file)
40+
with open(json_path, "r") as f:
41+
class_indict = json.load(f)
4242

4343
# create model
4444
model = create_model(num_classes=5).to(device)

‎pytorch_classification/Test2_alexnet/predict.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ def main():
3232
json_path = './class_indices.json'
3333
assert os.path.exists(json_path), "file: '{}' dose not exist.".format(json_path)
3434

35-
json_file = open(json_path, "r")
36-
class_indict = json.load(json_file)
35+
with open(json_path, "r") as f:
36+
class_indict = json.load(f)
3737

3838
# create model
3939
model = AlexNet(num_classes=5).to(device)

‎pytorch_classification/Test3_vggnet/predict.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ def main():
3131
json_path = './class_indices.json'
3232
assert os.path.exists(json_path), "file: '{}' dose not exist.".format(json_path)
3333

34-
json_file = open(json_path, "r")
35-
class_indict = json.load(json_file)
34+
with open(json_path, "r") as f:
35+
class_indict = json.load(f)
3636

3737
# create model
3838
model = vgg(model_name="vgg16", num_classes=5).to(device)

‎pytorch_classification/Test4_googlenet/predict.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ def main():
3131
json_path = './class_indices.json'
3232
assert os.path.exists(json_path), "file: '{}' dose not exist.".format(json_path)
3333

34-
json_file = open(json_path, "r")
35-
class_indict = json.load(json_file)
34+
with open(json_path, "r") as f:
35+
class_indict = json.load(f)
3636

3737
# create model
3838
model = GoogLeNet(num_classes=5, aux_logits=False).to(device)

‎pytorch_classification/Test5_resnet/predict.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ def main():
3232
json_path = './class_indices.json'
3333
assert os.path.exists(json_path), "file: '{}' dose not exist.".format(json_path)
3434

35-
json_file = open(json_path, "r")
36-
class_indict = json.load(json_file)
35+
with open(json_path, "r") as f:
36+
class_indict = json.load(f)
3737

3838
# create model
3939
model = resnet34(num_classes=5).to(device)

‎pytorch_classification/Test6_mobilenet/predict.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ def main():
3232
json_path = './class_indices.json'
3333
assert os.path.exists(json_path), "file: '{}' dose not exist.".format(json_path)
3434

35-
json_file = open(json_path, "r")
36-
class_indict = json.load(json_file)
35+
with open(json_path, "r") as f:
36+
class_indict = json.load(f)
3737

3838
# create model
3939
model = MobileNetV2(num_classes=5).to(device)

‎pytorch_classification/Test7_shufflenet/predict.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ def main():
3232
json_path = './class_indices.json'
3333
assert os.path.exists(json_path), "file: '{}' dose not exist.".format(json_path)
3434

35-
json_file = open(json_path, "r")
36-
class_indict = json.load(json_file)
35+
with open(json_path, "r") as f:
36+
class_indict = json.load(f)
3737

3838
# create model
3939
model = shufflenet_v2_x1_0(num_classes=5).to(device)

‎pytorch_classification/Test8_densenet/predict.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ def main():
3232
json_path = './class_indices.json'
3333
assert os.path.exists(json_path), "file: '{}' dose not exist.".format(json_path)
3434

35-
json_file = open(json_path, "r")
36-
class_indict = json.load(json_file)
35+
with open(json_path, "r") as f:
36+
class_indict = json.load(f)
3737

3838
# create model
3939
model = densenet121(num_classes=5).to(device)

‎pytorch_classification/Test9_efficientNet/predict.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ def main():
4242
json_path = './class_indices.json'
4343
assert os.path.exists(json_path), "file: '{}' dose not exist.".format(json_path)
4444

45-
json_file = open(json_path, "r")
46-
class_indict = json.load(json_file)
45+
with open(json_path, "r") as f:
46+
class_indict = json.load(f)
4747

4848
# create model
4949
model = create_model(num_classes=5).to(device)

‎pytorch_classification/swin_transformer/predict.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ def main():
3333
json_path = './class_indices.json'
3434
assert os.path.exists(json_path), "file: '{}' dose not exist.".format(json_path)
3535

36-
json_file = open(json_path, "r")
37-
class_indict = json.load(json_file)
36+
with open(json_path, "r") as f:
37+
class_indict = json.load(f)
3838

3939
# create model
4040
model = create_model(num_classes=5).to(device)

‎pytorch_classification/vision_transformer/predict.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ def main():
3232
json_path = './class_indices.json'
3333
assert os.path.exists(json_path), "file: '{}' dose not exist.".format(json_path)
3434

35-
json_file = open(json_path, "r")
36-
class_indict = json.load(json_file)
35+
with open(json_path, "r") as f:
36+
class_indict = json.load(f)
3737

3838
# create model
3939
model = create_model(num_classes=5, has_logits=False).to(device)

‎tensorflow_classification/ConvNeXt/predict.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ def main():
3535
json_path = './class_indices.json'
3636
assert os.path.exists(json_path), "file: '{}' dose not exist.".format(json_path)
3737

38-
json_file = open(json_path, "r")
39-
class_indict = json.load(json_file)
38+
with open(json_path, "r") as f:
39+
class_indict = json.load(f)
4040

4141
# create model
4242
model = create_model(num_classes=num_classes)

‎tensorflow_classification/Test11_efficientnetV2/predict.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ def main():
4040
json_path = './class_indices.json'
4141
assert os.path.exists(json_path), "file: '{}' dose not exist.".format(json_path)
4242

43-
json_file = open(json_path, "r")
44-
class_indict = json.load(json_file)
43+
with open(json_path, "r") as f:
44+
class_indict = json.load(f)
4545

4646
# create model
4747
model = create_model(num_classes=num_classes)

‎tensorflow_classification/Test2_alexnet/predict.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ def main():
3131
json_path = './class_indices.json'
3232
assert os.path.exists(json_path), "file: '{}' dose not exist.".format(json_path)
3333

34-
json_file = open(json_path, "r")
35-
class_indict = json.load(json_file)
34+
with open(json_path, "r") as f:
35+
class_indict = json.load(f)
3636

3737
# create model
3838
model = AlexNet_v1(num_classes=5)

‎tensorflow_classification/Test3_vgg/predict.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ def main():
3131
json_path = './class_indices.json'
3232
assert os.path.exists(json_path), "file: '{}' dose not exist.".format(json_path)
3333

34-
json_file = open(json_path, "r")
35-
class_indict = json.load(json_file)
34+
with open(json_path, "r") as f:
35+
class_indict = json.load(f)
3636

3737
# create model
3838
model = vgg("vgg16", im_height=im_height, im_width=im_width, num_classes=num_classes)

‎tensorflow_classification/Test4_goolenet/predict.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ def main():
3131
json_path = './class_indices.json'
3232
assert os.path.exists(json_path), "file: '{}' dose not exist.".format(json_path)
3333

34-
json_file = open(json_path, "r")
35-
class_indict = json.load(json_file)
34+
with open(json_path, "r") as f:
35+
class_indict = json.load(f)
3636

3737
model = GoogLeNet(class_num=5, aux_logits=False)
3838
model.summary()

‎tensorflow_classification/Test5_resnet/predict.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ def main():
3737
json_path = './class_indices.json'
3838
assert os.path.exists(json_path), "file: '{}' dose not exist.".format(json_path)
3939

40-
json_file = open(json_path, "r")
41-
class_indict = json.load(json_file)
40+
with open(json_path, "r") as f:
41+
class_indict = json.load(f)
4242

4343
# create model
4444
feature = resnet50(num_classes=num_classes, include_top=False)

‎tensorflow_classification/Test6_mobilenet/predict.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ def main():
3434
json_path = './class_indices.json'
3535
assert os.path.exists(json_path), "file: '{}' dose not exist.".format(json_path)
3636

37-
json_file = open(json_path, "r")
38-
class_indict = json.load(json_file)
37+
with open(json_path, "r") as f:
38+
class_indict = json.load(f)
3939

4040
# create model
4141
feature = MobileNetV2(include_top=False)

‎tensorflow_classification/Test7_shuffleNet/predict.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ def main():
3636
json_path = './class_indices.json'
3737
assert os.path.exists(json_path), "file: '{}' dose not exist.".format(json_path)
3838

39-
json_file = open(json_path, "r")
40-
class_indict = json.load(json_file)
39+
with open(json_path, "r") as f:
40+
class_indict = json.load(f)
4141

4242
# create model
4343
model = shufflenet_v2_x1_0(num_classes=num_classes)

‎tensorflow_classification/Test9_efficientNet/predict.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ def main():
4141
json_path = './class_indices.json'
4242
assert os.path.exists(json_path), "file: '{}' dose not exist.".format(json_path)
4343

44-
json_file = open(json_path, "r")
45-
class_indict = json.load(json_file)
44+
with open(json_path, "r") as f:
45+
class_indict = json.load(f)
4646

4747
# create model
4848
model = create_model(num_classes=num_classes)

‎tensorflow_classification/swin_transformer/predict.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ def main():
3535
json_path = './class_indices.json'
3636
assert os.path.exists(json_path), "file: '{}' dose not exist.".format(json_path)
3737

38-
json_file = open(json_path, "r")
39-
class_indict = json.load(json_file)
38+
with open(json_path, "r") as f:
39+
class_indict = json.load(f)
4040

4141
# create model
4242
model = create_model(num_classes=num_classes)

‎tensorflow_classification/vision_transformer/predict.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ def main():
3535
json_path = './class_indices.json'
3636
assert os.path.exists(json_path), "file: '{}' dose not exist.".format(json_path)
3737

38-
json_file = open(json_path, "r")
39-
class_indict = json.load(json_file)
38+
with open(json_path, "r") as f:
39+
class_indict = json.load(f)
4040

4141
# create model
4242
model = create_model(num_classes=num_classes, has_logits=False)

0 commit comments

Comments
 (0)
Please sign in to comment.