tensor_stream 1.0.7 → 1.0.8

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: 667188a4a1ebc020c6c03c2b8530505b26e0ccb80885e03abba16c09665d6247
4
- data.tar.gz: 06aebda0444eaa155d986324a0d4939bda66bbc6c6bc34762d83e46e1ba41fec
3
+ metadata.gz: 712b5d17b1b84d5289970fa578a8385c80e2a499033a42df8aadefdad654276c
4
+ data.tar.gz: ed74482c5913ea6debc5d0902d01c180b52f5028ae1ed7be726bafede9671982
5
5
  SHA512:
6
- metadata.gz: 309595e1452075516bd003a3ca99b5537430cef182000521ea951d9e51459356e236a64ea98216aeb4ea507313541ad702be6d67e3536102632af7a3ed6ca6fa
7
- data.tar.gz: 194174036aaee864f96cbbd7768f5b46a91a1592b0b9dd4a167c7071c063d92f2b62db26961a00ebace8eaece74caebe9232c04b4f741293b267dcdb215928e9
6
+ metadata.gz: 95b1715323930f35aeec861efa7b5dd96f9b61c8ea2d45343306798506cbbbc64e0092fed77c615a27e53b219610b7b14384726b5fb976b800c7ce57bcfc1539
7
+ data.tar.gz: 45e92e91167a39ca02cc5a1c04022c0dc1942ad863b650710b93862400174dbddd0bbe1889659ef55651bf1ca0b779420fd48811f862c8707be068cd02abed9f
@@ -1,5 +1,6 @@
1
1
  require "chunky_png"
2
2
 
3
+
3
4
  module TensorStream
4
5
  module ImagesOps
5
6
  def self.included(klass)
@@ -49,6 +50,23 @@ module TensorStream
49
50
  TensorShape.reshape(image_data, [image.height, image.width, channels])
50
51
  end
51
52
 
53
+ register_op :decode_jpg do |_context, tensor, inputs|
54
+ require "jpeg"
55
+
56
+ content = inputs[0]
57
+ channels = tensor.options[:channels]
58
+ channels = 3 if channels.zero?
59
+
60
+ image = Jpeg::Image.open_buffer(content)
61
+ image_data = image.raw_data.map do |pixel|
62
+ pixel.map!(&:to_f) if fp_type?(tensor.data_type)
63
+
64
+ pixel
65
+ end
66
+
67
+ TensorShape.reshape(image_data, [image.height, image.width, channels])
68
+ end
69
+
52
70
  register_op :encode_png do |_context, tensor, inputs|
53
71
  image_data = inputs[0]
54
72
  height, width, channels = shape_eval(image_data)
@@ -169,7 +169,7 @@ module TensorStream
169
169
  sorted = tensor.options[:sorted]
170
170
  work_values = TensorShape.reshape(values, [-1, v_shape.last])
171
171
  work_values.map! do |row|
172
- last_k = row.map.with_index { |r, index| [r, index] }.sort! { |a,b| a[0] <=> b[0] }.last(k) rescue binding.pry
172
+ last_k = row.map.with_index { |r, index| [r, index] }.sort! { |a,b| a[0] <=> b[0] }.last(k)
173
173
  last_k.reverse! if sorted
174
174
  last_k
175
175
  end
@@ -9,12 +9,12 @@ module TensorStream
9
9
 
10
10
  shape = tensor.options[:shape] || tensor.shape.shape
11
11
  fan_in, fan_out = if shape.size.zero?
12
- [1, 1]
13
- elsif shape.size == 1
14
- [1, shape[0]]
15
- else
16
- [shape[0], shape.last]
17
- end
12
+ [1, 1]
13
+ elsif shape.size == 1
14
+ [1, shape[0]]
15
+ else
16
+ [shape[0], shape.last]
17
+ end
18
18
 
19
19
  limit = Math.sqrt(6.0 / (fan_in + fan_out))
20
20
 
@@ -50,7 +50,7 @@ module TensorStream
50
50
  seed = tensor.options[:seed]
51
51
  random = _get_randomizer(tensor, seed)
52
52
  r = RandomGaussian.new(tensor.options.fetch(:mean), tensor.options.fetch(:stddev), -> { random.rand })
53
- random = _get_randomizer(tensor, seed)
53
+
54
54
  generator = -> { r.rand }
55
55
  shape = inputs[0] || tensor.shape.shape
56
56
  random_values = Array.new(shape.reduce(:*) || 1) {
@@ -75,9 +75,6 @@ module TensorStream
75
75
 
76
76
  norm_min = (minval - mean) / stddev
77
77
  norm_max = (maxval - mean) / stddev
78
- sqrt_factor = Math.sqrt((norm_min * norm_min) + 4.0)
79
- cutoff = 2.0 * Math.exp(0.5 + (norm_min * (norm_min - sqrt_factor)) / 4.0) / (norm_min + sqrt_factor)
80
- diff = norm_max - norm_min
81
78
 
82
79
  val = random_values.map { |v|
83
80
  iterations = 0
@@ -93,7 +90,6 @@ module TensorStream
93
90
 
94
91
  pick
95
92
  }
96
-
97
93
  TensorShape.reshape(val, shape)
98
94
  end
99
95
  end
@@ -49,12 +49,12 @@ module TensorStream
49
49
 
50
50
  child_context = execution_context.dup
51
51
  res = if tensor.is_a?(Operation)
52
- eval_operation(tensor, child_context)
53
- elsif !tensor.is_a?(Tensor)
54
- tensor
55
- else
56
- tensor.op
57
- end
52
+ eval_operation(tensor, child_context)
53
+ elsif !tensor.is_a?(Tensor)
54
+ tensor
55
+ else
56
+ tensor.op
57
+ end
58
58
  execution_context.deep_merge!(returns: child_context[:returns])
59
59
  res
60
60
  end
@@ -286,7 +286,7 @@ module TensorStream
286
286
  def eval_operation(tensor, child_context)
287
287
  return @context[tensor.name] if @context.key?(tensor.name)
288
288
 
289
- # puts "ruby eval #{object_id}: #{tensor.name}"
289
+ # puts "ruby eval #{tensor.operation} -> #{object_id}: #{tensor.name}"
290
290
  invoke(tensor, child_context).tap do |result|
291
291
  # puts "result done ruby #{object_id}: #{tensor.name}"
292
292
  # assertions to make sure inferred shapes == actual evaluated shapes
@@ -314,10 +314,10 @@ module TensorStream
314
314
  @context[tensor.name] = result
315
315
  end
316
316
  rescue EvaluatorExcecutionException => e
317
- raise e, "error #{e.message} while evaluating #{tensor.name} defined at #{tensor.source}"
317
+ raise e, "error #{e.message} while evaluating #{tensor.name} defined at #{tensor.source}"
318
318
  rescue TensorStreamError => e
319
- raise e, "error #{e.message} while evaluating #{tensor.name} defined at #{tensor.source}"
320
- rescue => e
319
+ raise e, "error #{e.message} while evaluating #{tensor.name} defined at #{tensor.source}"
320
+ rescue StandardError => e
321
321
  puts e.message
322
322
  puts e.backtrace.join("\n")
323
323
  raise EvaluatorExcecutionException.new(e, tensor), "error #{e.message} while evaluating #{tensor.name} : #{tensor.to_math(true, 1)} defined at #{tensor.source}"
@@ -7,6 +7,10 @@ module TensorStream
7
7
  _op(:decode_png, contents, channels: channels, data_type: dtype, name: name, new_shape: new_shape)
8
8
  end
9
9
 
10
+ def self.decode_jpeg(contents, channels: 0, dtype: :uint8, name: nil, new_shape: nil)
11
+ _op(:decode_jpg, contents, channels: channels, data_type: dtype, name: name, new_shape: new_shape)
12
+ end
13
+
10
14
  def self.encode_png(contents, compression: -1, name: nil, new_shape: nil, resample_method: nil)
11
15
  check_allowed_types(contents, %i[uint8 uint16])
12
16
  contents = convert_to_tensor(contents, dtype: :uint16)
@@ -70,9 +70,8 @@ module TensorStream
70
70
 
71
71
  ##
72
72
  # Outputs random values from a truncated normal distribution.
73
- def truncated_normal(shape, dtype: :float32, mean: 0.0, stddev: 1.0, seed: nil, name: nil)
74
- options = {dtype: dtype, mean: mean, stddev: stddev, seed: seed, name: name}
75
- _op(:truncated_normal, shape, options)
73
+ def truncated_normal(shape, dtype: :float32, mean: 0.0, stddev: 1.0, seed: nil, name: nil, pre_gen_table_size: nil)
74
+ _op(:truncated_normal, shape, dtype: dtype, mean: mean, stddev: stddev, seed: seed, name: name, pre_gen_table_size: pre_gen_table_size)
76
75
  end
77
76
 
78
77
  ##
@@ -1,5 +1,5 @@
1
1
  module TensorStream
2
- VERSION = "1.0.7".freeze
2
+ VERSION = "1.0.8".freeze
3
3
 
4
4
  def self.version
5
5
  VERSION
@@ -17,6 +17,7 @@ Gem::Specification.new do |spec|
17
17
  # to allow pushing to a single host or delete this section to allow pushing to any host.
18
18
  if spec.respond_to?(:metadata)
19
19
  spec.metadata["allowed_push_host"] = "https://rubygems.org"
20
+ spec.metadata["source_code_uri"] = "https://github.com/jedld/tensor_stream"
20
21
  spec.metadata["changelog_uri"] = "https://github.com/jedld/tensor_stream/blob/master/CHANGELOG.md"
21
22
  else
22
23
  raise "RubyGems 2.0 or newer is required to protect against " \
@@ -30,7 +31,7 @@ Gem::Specification.new do |spec|
30
31
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
32
  spec.require_paths = ["lib"]
32
33
 
33
- spec.add_development_dependency "bundler", "~> 1.14"
34
+ spec.add_development_dependency "bundler"
34
35
  spec.add_development_dependency "rake", "~> 10.0"
35
36
  spec.add_development_dependency "rspec", "~> 3.0"
36
37
  spec.add_development_dependency "awesome_print"
@@ -39,6 +40,7 @@ Gem::Specification.new do |spec|
39
40
  spec.add_development_dependency "pry-byebug"
40
41
  spec.add_development_dependency "byepry"
41
42
  spec.add_development_dependency "tensor_stream-opencl"
43
+ spec.add_dependency "jpeg"
42
44
  end
43
45
  spec.add_development_dependency "colorize"
44
46
  spec.add_development_dependency "rspec_junit_formatter"
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tensor_stream
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
4
+ version: 1.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joseph Emmanuel Dayo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-04-08 00:00:00.000000000 Z
11
+ date: 2019-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.14'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.14'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: jpeg
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: colorize
127
141
  requirement: !ruby/object:Gem::Requirement
@@ -435,6 +449,7 @@ licenses:
435
449
  - MIT
436
450
  metadata:
437
451
  allowed_push_host: https://rubygems.org
452
+ source_code_uri: https://github.com/jedld/tensor_stream
438
453
  changelog_uri: https://github.com/jedld/tensor_stream/blob/master/CHANGELOG.md
439
454
  post_install_message:
440
455
  rdoc_options: []
@@ -451,7 +466,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
451
466
  - !ruby/object:Gem::Version
452
467
  version: '0'
453
468
  requirements: []
454
- rubygems_version: 3.0.1
469
+ rubygems_version: 3.0.3
455
470
  signing_key:
456
471
  specification_version: 4
457
472
  summary: A Pure ruby tensorflow implementation