Class: DeepStack
- Inherits:
-
Object
- Object
- DeepStack
- Includes:
- CustomModel, Detection, Face, Image, Scene
- Defined in:
- lib/deep_stack/version.rb,
lib/deep_stack/face.rb,
lib/deep_stack/image.rb,
lib/deep_stack/scene.rb,
lib/deep_stack/detection.rb,
lib/deep_stack/deep_stack.rb,
lib/deep_stack/custom_model.rb
Overview
DeepStack API wrapper
All the methods that communicate with the server can raise an Errno::ECONNREFUSED
exception if the server is down or the connection details are incorrect.
Defined Under Namespace
Modules: CustomModel, Detection, Face, Image, Scene
Constant Summary collapse
- VERSION =
Returns Version of DeepStack helper libraries.
'1.6.1'
Instance Method Summary collapse
-
#api_post(path, *images, **args) ⇒ Hash
Make a POST request to DeepStack path target.
-
#close ⇒ Object
Close the persistent HTTP connection to DeepStack server.
-
#initialize(base_url, api_key: nil, admin_key: nil, verify_mode: nil) ⇒ DeepStack
constructor
Create a deepstack object for the given server URL.
Methods included from CustomModel
Methods included from Image
Methods included from Scene
Methods included from Detection
Methods included from Face
#delete_face, #delete_faces, #detect_faces, #face_list, #face_match, #recognize_faces, #register_face
Constructor Details
#initialize(base_url, api_key: nil, admin_key: nil, verify_mode: nil) ⇒ DeepStack
Create a deepstack object for the given server URL. HTTP connections are not made within the constructor so the deepstack object can be created against a server that’s currently down without raising an exception.
A persistent HTTP connection will be initiated on the first method request.
49 50 51 52 53 54 55 56 |
# File 'lib/deep_stack/deep_stack.rb', line 49 def initialize(base_url, api_key: nil, admin_key: nil, verify_mode: nil) @base_url = base_url @auth = { api_key: api_key, admin_key: admin_key }.select { |_k, v| v } # remove nil values uri = URI(base_url) @http = Net::HTTP.new(uri.hostname, uri.port) @http.use_ssl = uri.instance_of?(URI::HTTPS) @http.verify_mode = verify_mode if verify_mode end |
Instance Method Details
#api_post(path, *images, **args) ⇒ Hash
Make a POST request to DeepStack path target
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/deep_stack/deep_stack.rb', line 67 def api_post(path, *images, **args) uri = build_uri(path) args = @auth.merge(args) result = nil 10.times do result = images ? post_files(uri, images.flatten, **args) : post(uri, args) break unless result.is_a?(Net::HTTPRedirection) uri.path = result['location'] end raise Net::HTTPClientException, 'Too many redirections' if result.is_a?(Net::HTTPRedirection) process_result(result) end |
#close ⇒ Object
Close the persistent HTTP connection to DeepStack server. This should be called after a period of inactivity to close the TCP connection. Subsequent API calls will re-open the connection automatically.
88 89 90 |
# File 'lib/deep_stack/deep_stack.rb', line 88 def close @http.finish if @http&.started? end |