Skip to content
This repository was archived by the owner on Sep 7, 2022. It is now read-only.

Commit d3824e3

Browse files
committed
Fixes a bug causing generate_image.sh to fail on an unterminated string.
Adds padding to the base64 image in display_image.py if necessary. More safely extracts image data from the CloudML response using awk.
1 parent 60502f4 commit d3824e3

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

vae-gan/data/display_image.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,14 @@
2323
from PIL import Image
2424

2525
parser = argparse.ArgumentParser()
26-
parser.add_argument('--image', type=str, default='')
26+
parser.add_argument('--base64_image', type=str, default='')
2727
args, _ = parser.parse_known_args()
2828

29-
im = args.image.replace('_', '/').replace('-', '+')
29+
im = args.base64_image.replace('_', '/').replace('-', '+')
30+
31+
missing_base64_padding = len(im) % 4
32+
if missing_base64_padding != 0:
33+
im += ('=' * (4 - missing_base64_padding))
3034

3135
img = Image.open(cStringIO.StringIO(im.decode('base64')))
3236
img.show()

vae-gan/data/generate_image.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@ fi
5757

5858
JSON_OBJ=$(python create_random_embedding.py)
5959

60-
echo -e "${JSON_OBJ} > "${TMP_FILE}"
60+
echo -e "${JSON_OBJ}" > "${TMP_FILE}"
6161

6262
OUTPUT=$(gcloud ml-engine predict --model "${MODEL_NAME}" --json-instances "${TMP_FILE}")
63-
IMAGE=$(echo "${OUTPUT}"| cut -d' ' -f 4)
64-
65-
python display_image.py --image "${IMAGE}"
63+
IMAGE=$(echo "${OUTPUT}"| awk 'NR==2 {print $2}')
64+
python display_image.py --base64_image "${IMAGE}"

0 commit comments

Comments
 (0)