Skip to content

Commit 04cf4ee

Browse files
committed
Use anonymous boto client in examples/pytorch/image-classifier-resnet50/predictor.py
(cherry picked from commit 6be60b7)
1 parent e49a9f3 commit 04cf4ee

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

examples/pytorch/image-classifier-resnet50/predictor.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import requests
88
import re
99
import boto3
10+
from botocore import UNSIGNED
11+
from botocore.client import Config
1012
from torchvision import models, transforms, datasets
1113

1214

@@ -27,11 +29,16 @@ def __init__(self, config):
2729
classes = requests.get(config["classes"]).json()
2830
self.idx2label = [classes[str(k)][1] for k in range(len(classes))]
2931

32+
# create s3 client
33+
if os.environ.get("AWS_ACCESS_KEY_ID"):
34+
s3 = boto3.client("s3") # client will use your credentials if available
35+
else:
36+
s3 = boto3.client("s3", config=Config(signature_version=UNSIGNED)) # anonymous client
37+
3038
# download the model
3139
model_path = config["model_path"]
3240
model_name = config["model_name"]
3341
bucket, key = re.match("s3://(.+?)/(.+)", model_path).groups()
34-
s3 = boto3.client("s3")
3542
s3.download_file(bucket, os.path.join(key, model_name), model_name)
3643

3744
# load the model

examples/tensorflow/text-generator/encoder.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
# This file includes code which was modified from https://github.com/openai/gpt-2
44

5-
import boto3
65
import json
76
import regex
87
from functools import lru_cache

0 commit comments

Comments
 (0)