deepstack 1.3.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: be874725c205c1b4c704649e99506f362fc711eeff315d9616deb112f7caecd5
4
- data.tar.gz: f3a54bde1b2d8a533e9af9c58154a9004c7133f3e383d8e612a91d6052187fe1
3
+ metadata.gz: 830f650f0001d9ace30cbcf6758aa58cae9d4bf7089300f0e22261e58274e1cb
4
+ data.tar.gz: 2a9b1c9d03f3c04d6f159f9216b85791904f8c279155c9142bf5248eb719769a
5
5
  SHA512:
6
- metadata.gz: 9c7d7c9f0abe1465489936961e9cc297c1e9961b2e6afe6b2612fea975b5b0cc0c24a95748fd6fe14e5b45e480d15a27237ad5e5b01d4f84a8617258a659fcc1
7
- data.tar.gz: d4d9f966dd440a3cd3031c3ba64b029d0f94b427945d64b77cd23aea3f1a900de2fea85a2f24ddd49fca8c1c821c7e3c6b7c63a9e120fc38e481ed1452ec388b
6
+ metadata.gz: fc573a46b62325ef299af50d25a7c9c760df25025f87f1c8c1eb588a3ee148fceb38ace946d3d39e92236d48c96da4f474a239ecfc2821660886e6f020b77ea4
7
+ data.tar.gz: '08e0a71c109b87a81ef475aa85e8ea2750ed615adf65a03299b4b3df805911fac898597f94a4cdb5aa597fa03fab6367ccf04004c7545980e3a6b2261ff86d1d'
@@ -1,10 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class DeepStack
4
- # Custom Model
4
+ # Support for using Custom Models with DeepStack
5
5
  module CustomModel
6
6
  #
7
- # Return predictions using a custom model
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
8
10
  #
9
11
  # @param [String] model custom model name
10
12
  # @param [Object] image binary data or a File object
@@ -6,6 +6,7 @@ require_relative 'face'
6
6
  require_relative 'detection'
7
7
  require_relative 'scene'
8
8
  require_relative 'custom_model'
9
+ require_relative 'image'
9
10
  require_relative 'version'
10
11
 
11
12
  # DeepStack API
@@ -13,6 +14,7 @@ class DeepStack
13
14
  include DeepStack::Face
14
15
  include DeepStack::Detection
15
16
  include DeepStack::Scene
17
+ include DeepStack::Image
16
18
  include DeepStack::CustomModel
17
19
 
18
20
  #
@@ -20,15 +22,27 @@ class DeepStack
20
22
  #
21
23
  # @param [String] base_url the url to DeepStack's server:port
22
24
  # @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
25
+ # @param [String] api_key an optional API-KEY to use when connecting to DeepStack
26
+ # @param [Integer] verify_mode sets the flags for server the certification verification at
27
+ # beginning of SSL/TLS session.
28
+ # +OpenSSL::SSL::VERIFY_NONE+ or +OpenSSL::SSL::VERIFY_PEER+ are acceptable.
24
29
  #
25
30
  # @example
26
31
  # DeepStack.new('http://127.0.0.1:5000')
27
32
  #
28
- def initialize(base_url, api_key: nil, admin_key: nil)
33
+ # # Using API KEY:
34
+ # DeepStack.new('http://127.0.0.1:5000', api_key: 'secret', admin_key: 'supersecret')
35
+ #
36
+ # # Connect to SSL with a self-signed certificate
37
+ # DeepStack.new('https://localhost:443', verify_mode: OpenSSL::SSL::VERIFY_NONE)
38
+ #
39
+ def initialize(base_url, api_key: nil, admin_key: nil, verify_mode: nil)
29
40
  @base_url = base_url
30
41
  @auth = { api_key: api_key, admin_key: admin_key }.select { |_k, v| v } # remove nil values
31
- @http_mutex = Mutex.new
42
+ uri = URI(base_url)
43
+ http_options = {}
44
+ http_options[:verify_mode] = verify_mode if verify_mode
45
+ @http = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.instance_of?(URI::HTTPS), **http_options)
32
46
  end
33
47
 
34
48
  #
@@ -60,9 +74,7 @@ class DeepStack
60
74
  # Close the HTTP connection to DeepStack server
61
75
  #
62
76
  def close
63
- @http_mutex.synchronize do
64
- @http.finish if @http&.started?
65
- end
77
+ @http.finish if @http&.started?
66
78
  end
67
79
 
68
80
  private
@@ -79,11 +91,8 @@ class DeepStack
79
91
  form_data = combine_images_and_args(images.flatten, **args)
80
92
  req = Net::HTTP::Post.new(uri)
81
93
  req.set_form(form_data, 'multipart/form-data')
82
- @http_mutex.synchronize do
83
- @http ||= Net::HTTP.start(uri.hostname, uri.port)
84
- @http.start unless @http.started?
85
- @http.request(req)
86
- end
94
+ @http.start unless @http.started?
95
+ @http.request(req)
87
96
  end
88
97
 
89
98
  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
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'base64'
4
+
5
+ class DeepStack
6
+ # Support Image Enhance feature
7
+ module Image
8
+ #
9
+ # Enhance image {https://docs.deepstack.cc/api-reference/index.html#image-enhance}
10
+ #
11
+ # @param [Image] image the raw image data or a File object of an image file
12
+ #
13
+ # @return [Image] the enhanced image object
14
+ # @return [nil] if failed
15
+ #
16
+ def enhance_image(image)
17
+ target = 'vision/enhance'
18
+ result = api_post(target, image)
19
+ return unless result&.dig('success') == true
20
+
21
+ Base64.decode64(result['base64'])
22
+ end
23
+ end
24
+ 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.3.0'
8
+ VERSION = '1.6.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.3.0
4
+ version: 1.6.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:
@@ -21,6 +21,7 @@ files:
21
21
  - lib/deep_stack/deep_stack.rb
22
22
  - lib/deep_stack/detection.rb
23
23
  - lib/deep_stack/face.rb
24
+ - lib/deep_stack/image.rb
24
25
  - lib/deep_stack/scene.rb
25
26
  - lib/deep_stack/version.rb
26
27
  - lib/deepstack.rb