deepstack 1.1.1 → 1.4.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: b13995c10316b274d2b292316076cf96c96f945ac7304835ca5dc25fd873eaeb
4
- data.tar.gz: 585b76987b8d1db73e05e78b777bf6fcd716e38f40c7c1e9b9150a7c833d84ec
3
+ metadata.gz: '02929889eabbeeb8b76cd2f588cef7452ef0bb6dd3687fad749105e6956191e9'
4
+ data.tar.gz: 2625f0bc5aac522d23461530dda2e581718c4f967c053db13c13ff0dcaa46f92
5
5
  SHA512:
6
- metadata.gz: 41f4207559f4976ebf42864186661a538f6d45978958ec22a951c2e1ddac17685c67a2050de1064fe070c10f39fd9d3b954807be40bd04b14be5cf4e24221e5c
7
- data.tar.gz: ceac07d54df401e92619d2c48e493ced1e6b2543a71bfe8dc79ccb5b1be53e34aa96d38eaf395b6bfbd919739c7476a886fac54fdb1fb9bf945a60cce6c0bba4
6
+ metadata.gz: fd37e76b9ad0fd30ddcc8a995fe2267d01f056cb3aa3a1d134b6335d91b6b300f61ce9929ab6b2e183ead1036135d2854a53858306395caadfaca7f2baf083d2
7
+ data.tar.gz: 275bba97d88a57d51de45a0ae2be230df5d2a8c749324ea748cd2a16c9e45de9c8f6c44d0d61fd860985400093e1caec636f1905bfbcab680631b39087bfbffa
@@ -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
@@ -1,12 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'pp'
4
3
  require 'net/http'
5
4
  require 'json'
6
5
  require_relative 'face'
7
6
  require_relative 'detection'
8
7
  require_relative 'scene'
9
- require_relative 'custom'
8
+ require_relative 'custom_model'
10
9
  require_relative 'version'
11
10
 
12
11
  # DeepStack API
@@ -14,11 +13,21 @@ class DeepStack
14
13
  include DeepStack::Face
15
14
  include DeepStack::Detection
16
15
  include DeepStack::Scene
17
- include DeepStack::Custom
16
+ include DeepStack::CustomModel
18
17
 
18
+ #
19
19
  # Create a deepstack object connected to the given URL
20
- def initialize(base_url)
20
+ #
21
+ # @param [String] base_url the url to DeepStack's server:port
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
24
+ #
25
+ # @example
26
+ # DeepStack.new('http://127.0.0.1:5000')
27
+ #
28
+ def initialize(base_url, api_key: nil, admin_key: nil)
21
29
  @base_url = base_url
30
+ @auth = { api_key: api_key, admin_key: admin_key }.select { |_k, v| v } # remove nil values
22
31
  @http_mutex = Mutex.new
23
32
  end
24
33
 
@@ -33,6 +42,7 @@ class DeepStack
33
42
  #
34
43
  def api_post(path, *images, **args)
35
44
  uri = build_uri(path)
45
+ args = @auth.merge(args)
36
46
 
37
47
  result = nil
38
48
  10.times do
@@ -51,8 +61,7 @@ class DeepStack
51
61
  #
52
62
  def close
53
63
  @http_mutex.synchronize do
54
- @http&.finish
55
- @http = nil
64
+ @http.finish if @http&.started?
56
65
  end
57
66
  end
58
67
 
@@ -72,6 +81,7 @@ class DeepStack
72
81
  req.set_form(form_data, 'multipart/form-data')
73
82
  @http_mutex.synchronize do
74
83
  @http ||= Net::HTTP.start(uri.hostname, uri.port)
84
+ @http.start unless @http.started?
75
85
  @http.request(req)
76
86
  end
77
87
  end
@@ -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
@@ -5,5 +5,5 @@
5
5
  #
6
6
  class DeepStack
7
7
  # @return [String] Version of DeepStack helper libraries
8
- VERSION = '1.1.1'
8
+ VERSION = '1.4.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.1.1
4
+ version: 1.4.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-10 00:00:00.000000000 Z
11
+ date: 2022-05-11 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