def publish_image(face_im, adv_im, combined_im, confidence=0.0, hack=False):
"""convert png; base64 encode that and post to stat server"""
# Do face
text_buf = io.BytesIO()
png.from_array(face_im, 'RGB').save(text_buf)
encoded_face = b"data:image/png;base64,"+base64.b64encode(text_buf.getvalue(),b'#/')
# Do adv
text_buf = io.BytesIO()
png.from_array(adv_im, 'RGB').save(text_buf)
encoded_adv = b"data:image/png;base64," + base64.b64encode(text_buf.getvalue(),b'#/')
# Do combined
text_buf = io.BytesIO()
png.from_array(combined_im, 'RGB').save(text_buf)
encoded_combined = b"data:image/png;base64," + base64.b64encode(text_buf.getvalue(),b'#/')
url = "http://facejack.westeurope.cloudapp.azure.com:5000/push_stats"
if hack:
payload = b"adversarial=yes&original_img=" + encoded_face + \
b"&adv_mod_img=" + encoded_adv + \
b"&modified_img=" + encoded_combined + \
b"&confidence=" + str(confidence * 100).encode()
else:
payload = b"adversarial=no&original_img="+encoded_face+\
b"&adv_mod_img="+encoded_adv+\
b"&modified_img="+encoded_combined+\
b"&confidence="+str(confidence*100).encode()
headers = {
'content-type': "application/x-www-form-urlencoded",
'cache-control': "no-cache"
}
response = requests.request("POST", url, data=payload, headers=headers, )
评论列表
文章目录