Skip to content

Vision a11 - adding crop hints and web annotation - #671

Merged
theacodes merged 12 commits into
masterfrom
vision_a11
Nov 22, 2016
Merged

Vision a11 - adding crop hints and web annotation#671
theacodes merged 12 commits into
masterfrom
vision_a11

Conversation

@puneith

@puneithpuneith commented Nov 18, 2016

Copy link
Copy Markdown
Contributor

@jonparrott@tswast Please review. Alpha 1.1 changes.

@puneithpuneith added do not merge Indicates a pull request not ready for merge, due to either quality or timing. In Progress labels Nov 18, 2016
@googlebotgooglebot added the cla: yes This human has signed the Contributor License Agreement. label Nov 18, 2016

@tswasttswast left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some general comments. I assume @jonparrott will have others.

@@ -0,0 +1,97 @@
#!/usr/bin/env python
# Copyright 2015 Google Inc. All Rights Reserved.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I don't think the header on go/releasing/preparing includes "All Rights Reserved" anymore.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

discoveryServiceUrl=DISCOVERY_URL)


def crop_hint(photo_file):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

photo_file makes me think this is a file object. Prefer photo_path.

(Update here and in the other functions)

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@puneith

puneith commented Nov 21, 2016

Copy link
Copy Markdown
ContributorAuthor

@jonparrott The tests are successful locally. Any ideas why one of the three fails? It looks like the response is not as expected, but I can't tell why.

@theacodes

Copy link
Copy Markdown
Contributor

@puneith the response list is empty:

(Pdb) result
{u'responses': [{}]}

Comment threadvision/api/label/snippets.py Outdated

import argparse
import base64
import httplib2

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

httplib2 is a third-party import.

Comment threadvision/api/label/snippets.py Outdated
from googleapiclient import discovery
from oauth2client.client import GoogleCredentials

DISCOVERY_URL = ('https://vision.googleapis.com/$discovery/rest?'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Break after opening (, please.

credentials = GoogleCredentials.get_application_default()
scoped_credentials = credentials.create_scoped(
['https://www.googleapis.com/auth/cloud-platform'])
http = httplib2.Http()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know I ask this constantly, but is this needed because of alpha?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Comment threadvision/api/label/snippets.py Outdated
['https://www.googleapis.com/auth/cloud-platform'])
http = httplib2.Http()
scoped_credentials.authorize(http)
return discovery.build('vision', 'v1',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Break after opening (, please.

Comment threadvision/api/label/snippets.py Outdated

with open(photo_path, 'rb') as image:
image_content = base64.b64encode(image.read())
service_request = service.images().annotate(body={

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your with statement covers too many things. It only needs to cover the image.read call.

service = get_service()

with open(photo_path, 'rb') as image:
image_content = base64.b64encode(image.read())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here on the with statement.

Comment threadvision/api/label/snippets.py Outdated

if args.command == 'crop_hint':
response = crop_hint(args.image_path)
print(json.dumps(response, indent=2))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer printing the result in the sample functions themselves.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer printing outside because then I can test easily. Otherwise I have to use capsys and parse the output again.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our samples should not be structured around our tests, it should be the other way around. Please be consistent with the other samples.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually tests are a good way to find if the code is written properly. In this case testing become bit tedious if you print in the function vs the other option.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can have a separate conversation if you want to propose a change to the Python sample style, but for now, can you please be consistent?

Comment threadvision/api/label/snippets_test.py Outdated
crop_hint_annotation = crop_hint['cropHintsAnnotation']['cropHints'][0]
confidence = crop_hint_annotation['confidence']

assert confidence > 0.5

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try assert 0.5 < confidence < 0.9

@puneith

Copy link
Copy Markdown
ContributorAuthor

@gguuss fyi

@theacodes

Copy link
Copy Markdown
Contributor

@tswast can you approve changes?

@puneith

Copy link
Copy Markdown
ContributorAuthor

@jonparrott Now that this is finally green can you please merge.

@puneith

Copy link
Copy Markdown
ContributorAuthor

@dpebot Do I have powers to ask you to merge?

@theacodes
theacodes merged commit 504ae46 into masterNov 22, 2016
@theacodes
theacodes deleted the vision_a11 branch November 22, 2016 05:39
chalmerlowe pushed a commit that referenced this pull request Apr 7, 2026
* samples: delete unspecified sample
* fixed lint issue
* updated readme
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yesThis human has signed the Contributor License Agreement.do not mergeIndicates a pull request not ready for merge, due to either quality or timing.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@puneith@theacodes@tswast@googlebot@puneithk