1 / 19

Module interface design example: Hiding dependence on face

Module interface design example: Hiding dependence on face.com. face.com is pretty good, but ... . a better service might come along later, or face detection might be supported in hardware, or face.com might go out of business, or face.com might start charging too much, or

rasia
Download Presentation

Module interface design example: Hiding dependence on face

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Module interface design example: Hiding dependence on face.com

  2. face.com is pretty good, but ... a better service might come along later, or face detection might be supported in hardware, or face.com might go out of business, or face.com might start charging too much, or face.com might not support a feature we need later so ... we might want to limit our dependence on that particular service ... like a device-hiding module

  3. but face4j is pretty good! • We could use the face4j API directly • + It’s already written • + It’s (probably) pretty well tested, and works • It is somewhat more complex than we need • It does not protect us from changes

  4. A thin veneer ...

  5. What should we hide? What are some things that might differ between face recognition services and devices?

  6. What should we hide? (Some possibilities) Accepted photograph formats & sources Identifiers (unique face tags) Authentication and rate limiting Detect/Recognize protocol Confidence filtering Options (e.g., “aggressive” mode)

  7. We’d like it to be simple ... Recognize: Input: A photo (jpg format) Output: Identified person It’s not going to be quite that simple, though ... what else will the interface need to include?

  8. Complications of the API • Authentication • How can we authenticate, without making other parts of our application dependent on face.com? • Exceptional conditions • Not exactly the face4j exceptions (?), but we need to consider the exceptional conditions • What’s a “user id”? What’s a “namespace”? • Might differ from service to service

  9. Namespaces and IDs With face.com, user IDs are associated with tags in facebook, twitter, or private namespaces Assume we want private namespaces ... How do we abstract to something that could use a different photo identification service?

  10. Abstracting Namespace • A namespace is a collection of user records • Conceptually similar to a “map” or “dictionary” structure, like a Java hashmap or treemap. • Difference: keys are not unique objects • Face.comUIDs are strings (“name@space”) • Other services might use a different kind of key. What should we do? • Suggestion: We could map other key types to strings, if needed for another service.

  11. What can we assume? Ideally we should look at 3-4 face identification services ... what do they have in common? But we don’t have other examples yet. What can we assume about handling face recognition databases, like face.com name spaces? Can we any useful service requires something like name spaces?

  12. What to assume Any useful face recognition service will look up faces in a “logical database” (like a name space) But ... The database might be local or remote Keys might not be uid@namespace UIDs and name spaces might not be strings

  13. face4j client code FaceClientfaceClient= new DefaultFaceClient(API_KEY, API_SEC); Photo photo = faceClient.detect(URL_WITH_FACES).get(0); Face f = photo.getFace(); faceClient.saveTags(f.getTID(), “id@namespace”, “label"); faceClient.train(USER_ID); photo = faceClient.recognize(URL_WITH_FACES, "all@yournamespace").get(0);

  14. face4j client code Since authorization could vary, how it occurs should be a secret of the module. We’ll either have a no-argument constructor or a constructor that does NOT take face.com-specific API keys and secrets. FaceClientfaceClient= new DefaultFaceClient(API_KEY, API_SEC); Photo photo = faceClient.detect(URL_WITH_FACES).get(0); Face f = photo.getFace(); faceClient.saveTags(f.getTID(), “id@namespace”, “label"); faceClient.train(USER_ID); photo = faceClient.recognize(URL_WITH_FACES, "all@yournamespace").get(0);

  15. face4j client code Just a name/value table. Wrap? Detect/recognize sequence might vary ... probably safest to wrap the whole sequence FaceClientfaceClient= new DefaultFaceClient(API_KEY, API_SEC); Photo photo = faceClient.detect(URL_WITH_FACES).get(0); Face f = photo.getFace(); faceClient.saveTags(f.getTID(), “id@namespace”, “label"); faceClient.train(USER_ID); photo = faceClient.recognize(URL_WITH_FACES, "all@yournamespace").get(0);

  16. face4j client code One method for detect/getFace/saveTags/train sequence (maybe for a set of photos?) FaceClientfaceClient= new DefaultFaceClient(API_KEY, API_SEC); Photo photo = faceClient.detect(URL_WITH_FACES).get(0); Face f = photo.getFace(); faceClient.saveTags(f.getTID(), “id@namespace”, “label"); faceClient.train(USER_ID); photo = faceClient.recognize(URL_WITH_FACES, "all@yournamespace").get(0);

  17. face4j client code One method for recognition, abstracting the namespace identifier and possibly the image specification FaceClientfaceClient= new DefaultFaceClient(API_KEY, API_SEC); Photo photo = faceClient.detect(URL_WITH_FACES).get(0); Face f = photo.getFace(); faceClient.saveTags(f.getTID(), “id@namespace”, “label"); faceClient.train(USER_ID); photo = faceClient.recognize(URL_WITH_FACES, "all@yournamespace").get(0);

  18. Specifying the Interface Javadoc (or Doxygen, or ... ) is a reasonable choice Specify more than the signatures When is it legal to call this method? How does the method change the (logical) state of the object? When can exceptions occur? What do they mean? ...

  19. from face4j FaceClient.java /** * Convenience method for detecting faces in an image file * * @paramimageUrl {@link File} of the image to be uploaded to face.com for detection * @paramuids comma delimited {@code String} of user IDs to search for in the photos passed in the request * * @return {@link Photo} * * @throws FaceServerException * @throws FaceClientException * * * @see {@link #recognize(String, String)} */ public Photo recognize (final File imageFile, final String uids) throws FaceClientException, FaceServerException;

More Related