deepstack 1.2.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: caf4cf801a5a99ff308e5afc06ed19dac86d8348388c519880770d482fd1bb0b
4
- data.tar.gz: de77bacb1bd1ffb46c4dff277ab16e1195ef423f005ad98394b49cab6e248fa3
3
+ metadata.gz: 6d3a74d72c68a1aef4f04d6b3a04d67cb26c89daf0bdfa1ba85a1cbfd904bd76
4
+ data.tar.gz: 2cc1bfddab42ebbc72ef9e1a90c35cc577e5a46e0db8d3900c42bc24dd15af64
5
5
  SHA512:
6
- metadata.gz: 6836c3bc1e6dc367542c4bd9e3e089ddf2cf3a7e612d6230dfabf3f3a38a4651965eead00bba50dd5916e5a9d8fcc44c624f3743b17165fbda24cff8c9ea7ec8
7
- data.tar.gz: 5f5c98987f6fae82a67ef8fa57a557aa300bd22da6108a8575eabe6e3ac8d1f301f57caad1f86b533629b503d53db4bb40e101ff630abddce1b2659637e2b177
6
+ metadata.gz: b12be0063b456923b065db6d9ae277aa30a32bc2a4e1c895a646b039d4770bd36dd296effc788cb7ace506be23dd64a836d11e77210184eb278b0b82ddda1818
7
+ data.tar.gz: ed627f25f85c15551b0758e9d87ea002f0cb95efdec5a6c31a92dd9a11936fc7bdddf51a570e61ebffc5995ce869c17d703df277421578428c187f7a724d64d5
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ class DeepStack
4
+ # Support for using Custom Models with DeepStack
5
+ module CustomModel
6
+ #
7
+ # Return predictions using a custom model.
8
+ # Custom models are *.pt models that have been saved in DeepStack's modelstore directory.
9
+ # See https://docs.deepstack.cc/custom-models/deployment/index.html
10
+ #
11
+ # @param [String] model custom model name
12
+ # @param [Object] image binary data or a File object
13
+ # @param [Hash] options additional fields for DeepStack, e.g. min_confidence: 0.5
14
+ #
15
+ # @return [Array] if successful, an array of DeepStack predictions
16
+ #
17
+ # @return [nil] if error
18
+ #
19
+ def custom_model(model, image, **options)
20
+ target = "vision/custom/#{model}"
21
+ api_post(target, image, **options)&.dig('predictions')
22
+ end
23
+ # @deprecated Use {custom_model} instead
24
+ alias custom_inference custom_model
25
+ end
26
+ end
@@ -5,7 +5,7 @@ require 'json'
5
5
  require_relative 'face'
6
6
  require_relative 'detection'
7
7
  require_relative 'scene'
8
- require_relative 'custom'
8
+ require_relative 'custom_model'
9
9
  require_relative 'version'
10
10
 
11
11
  # DeepStack API
@@ -13,22 +13,34 @@ class DeepStack
13
13
  include DeepStack::Face
14
14
  include DeepStack::Detection
15
15
  include DeepStack::Scene
16
- include DeepStack::Custom
16
+ include DeepStack::CustomModel
17
17
 
18
18
  #
19
19
  # Create a deepstack object connected to the given URL
20
20
  #
21
21
  # @param [String] base_url the url to DeepStack's server:port
22
22
  # @param [String] api_key an optional API-KEY to use when connecting to DeepStack
23
- # @param [String] admin_key an optional ADMIN-KEY to use when connecting to DeepStack
23
+ # @param [String] api_key an optional API-KEY to use when connecting to DeepStack
24
+ # @param [Integer] verify_mode sets the flags for server the certification verification at
25
+ # beginning of SSL/TLS session.
26
+ # +OpenSSL::SSL::VERIFY_NONE+ or +OpenSSL::SSL::VERIFY_PEER+ are acceptable.
24
27
  #
25
28
  # @example
26
29
  # DeepStack.new('http://127.0.0.1:5000')
27
30
  #
28
- def initialize(base_url, api_key: nil, admin_key: nil)
31
+ # # Using API KEY:
32
+ # DeepStack.new('http://127.0.0.1:5000', api_key: 'secret', admin_key: 'supersecret')
33
+ #
34
+ # # Connect to SSL with a self-signed certificate
35
+ # DeepStack.new('https://localhost:443', verify_mode: OpenSSL::SSL::VERIFY_NONE)
36
+ #
37
+ def initialize(base_url, api_key: nil, admin_key: nil, verify_mode: nil)
29
38
  @base_url = base_url
30
39
  @auth = { api_key: api_key, admin_key: admin_key }.select { |_k, v| v } # remove nil values
31
- @http_mutex = Mutex.new
40
+ uri = URI(base_url)
41
+ http_options = {}
42
+ http_options[:verify_mode] = verify_mode if verify_mode
43
+ @http = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.instance_of?(URI::HTTPS), **http_options)
32
44
  end
33
45
 
34
46
  #
@@ -60,10 +72,7 @@ class DeepStack
60
72
  # Close the HTTP connection to DeepStack server
61
73
  #
62
74
  def close
63
- @http_mutex.synchronize do
64
- @http&.finish
65
- @http = nil
66
- end
75
+ @http.finish if @http&.started?
67
76
  end
68
77
 
69
78
  private
@@ -80,10 +89,8 @@ class DeepStack
80
89
  form_data = combine_images_and_args(images.flatten, **args)
81
90
  req = Net::HTTP::Post.new(uri)
82
91
  req.set_form(form_data, 'multipart/form-data')
83
- @http_mutex.synchronize do
84
- @http ||= Net::HTTP.start(uri.hostname, uri.port)
85
- @http.request(req)
86
- end
92
+ @http.start unless @http.started?
93
+ @http.request(req)
87
94
  end
88
95
 
89
96
  def combine_images_and_args(*images, **args)
@@ -77,5 +77,24 @@ class DeepStack
77
77
  target = 'vision/face/register'
78
78
  api_post(target, images, userid: userid)&.dig('success') == true
79
79
  end
80
+
81
+ #
82
+ # Call DeepStack's Face Match service. Compare two different pictures and tells the similarity between them.
83
+ #
84
+ # @example
85
+ # image1 = File.read('obama1.jpg')
86
+ # image2 = File.read('obama2.jpg')
87
+ # puts deepstack.face_match(image1, image2) > 0.6 ? 'similar' : 'different'
88
+ #
89
+ # @param [Array] *images two images to compare
90
+ # @param [kwargs] **args optional arguments to the API call
91
+ #
92
+ # @return [Float] The similarity score (0-1)
93
+ # @return [nil] if failed
94
+ #
95
+ def face_match(*images, **args)
96
+ target = 'vision/face/match'
97
+ api_post(target, images, **args)&.dig('similarity')
98
+ end
80
99
  end
81
100
  end
@@ -4,14 +4,15 @@ class DeepStack
4
4
  # Scene Recognition
5
5
  module Scene
6
6
  #
7
- # Return
7
+ # Call the scene recognition API to classify an image into one of the supported scenes.
8
8
  #
9
9
  # @param [Object] image binary data or a File object
10
10
  # @param [Hash] options additional fields for DeepStack, e.g. min_confidence: 0.5
11
11
  #
12
- # @return [Hash] if successful, DeepStack result hash {'label' => 'scene', 'confidence' => 2.2}
12
+ # @return [Hash] if successful, DeepStack result hash +{'label' => 'scene', 'confidence' => 2.2}+
13
13
  #
14
14
  # @return [nil] if error
15
+ #
15
16
  def identify_scene(image, **options)
16
17
  target = 'vision/scene'
17
18
  api_post(target, image, **options)
@@ -5,5 +5,5 @@
5
5
  #
6
6
  class DeepStack
7
7
  # @return [String] Version of DeepStack helper libraries
8
- VERSION = '1.2.0'
8
+ VERSION = '1.5.0'
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deepstack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jimmy Tanagra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-11 00:00:00.000000000 Z
11
+ date: 2022-05-12 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -17,7 +17,7 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
- - lib/deep_stack/custom.rb
20
+ - lib/deep_stack/custom_model.rb
21
21
  - lib/deep_stack/deep_stack.rb
22
22
  - lib/deep_stack/detection.rb
23
23
  - lib/deep_stack/face.rb
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class DeepStack
4
- # Custom Model
5
- module Custom
6
- #
7
- # Register a custom inference method for convenience.
8
- # The custom method is called "identify_<modelname>"
9
- # Example:
10
- # deepstack.register_custom_model('license_plate')
11
- # deepstack.identify_license_plate(image)
12
- #
13
- # @param [Array] models a list of one or more custom model names to register
14
- #
15
- # @return [<Type>] <description>
16
- #
17
- def self.register_model(*models)
18
- models.flatten.each do |model|
19
- method_name = 'identify_'.concat model.gsub(/-+/, '_') # convert - to _
20
- define_method(method_name) do |image, **options|
21
- custom_inference(model, image, options)
22
- end
23
- end
24
- end
25
-
26
- #
27
- # Return predictions using a custom model
28
- #
29
- # @param [String] model custom model name
30
- # @param [Object] image binary data or a File object
31
- # @param [Hash] options additional fields for DeepStack, e.g. min_confidence: 0.5
32
- #
33
- # @return [Array] if successful, an array of DeepStack predictions
34
- #
35
- # @return [nil] if error
36
- #
37
- def custom_inference(model, image, **options)
38
- target = "vision/custom/#{model}"
39
- api_post(target, image, options)&.dig('predictions')
40
- end
41
- end
42
- end