| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7a828c0 commit a596dbe
11 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -62,6 +62,33 @@ A FIFOQueue that supports batching variable-sized tensors by padding. A `Padding | |||
| 62 | 62 | ||
| 63 | 63 | A queue implementation that dequeues elements in prioritized order. A `PriorityQueue` has bounded capacity; supports multiple concurrent producers and consumers; and provides exactly-once delivery. A `PriorityQueue` holds a list of up to `capacity` elements. Each element is a fixed-length tuple of tensors whose dtypes are described by `types`, and whose shapes are optionally described by the `shapes` argument. | |
| 64 | 64 | ||
| 65 | + ```csharp | ||
| 66 | + [TestMethod] | ||
| 67 | + public void PriorityQueue() | ||
| 68 | + { | ||
| 69 | + var queue = tf.PriorityQueue(3, tf.@string); | ||
| 70 | + var init = queue.enqueue_many(new[] { 2L, 4L, 3L }, new[] { "p1", "p2", "p3" }); | ||
| 71 | + var x = queue.dequeue(); | ||
| 72 | + | ||
| 73 | + using (var sess = tf.Session()) | ||
| 74 | + { | ||
| 75 | + init.run(); | ||
| 76 | + | ||
| 77 | + // output will 2, 3, 4 | ||
| 78 | + var result = sess.run(x); | ||
| 79 | + Assert.AreEqual(result[0].GetInt64(), 2L); | ||
| 80 | + | ||
| 81 | + result = sess.run(x); | ||
| 82 | + Assert.AreEqual(result[0].GetInt64(), 3L); | ||
| 83 | + | ||
| 84 | + result = sess.run(x); | ||
| 85 | + Assert.AreEqual(result[0].GetInt64(), 4L); | ||
| 86 | + } | ||
| 87 | + } | ||
| 88 | + ``` | ||
| 89 | + | ||
| 90 | + | ||
| 91 | + | ||
| 65 | 92 | #### RandomShuffleQueue | |
| 66 | 93 | ||
| 67 | 94 | A queue implementation that dequeues elements in a random order. A `RandomShuffleQueue` has bounded capacity; supports multiple concurrent producers and consumers; and provides exactly-once delivery. A `RandomShuffleQueue` holds a list of up to `capacity` elements. Each element is a fixed-length tuple of tensors whose dtypes are described by `dtypes`, and whose shapes are optionally described by the `shapes` argument. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -50,7 +50,7 @@ public PaddingFIFOQueue PaddingFIFOQueue(int capacity, | |||
| 50 | 50 | string shared_name = null, | |
| 51 | 51 | string name = "padding_fifo_queue") | |
| 52 | 52 | => new PaddingFIFOQueue(capacity, | |
| 53 | - new [] { dtype }, | ||
| 53 | + new[] { dtype }, | ||
| 54 | 54 | new[] { shape }, | |
| 55 | 55 | shared_name: shared_name, | |
| 56 | 56 | name: name); | |
@@ -86,7 +86,26 @@ public FIFOQueue FIFOQueue(int capacity, | |||
| 86 | 86 | => new FIFOQueue(capacity, | |
| 87 | 87 | new[] { dtype }, | |
| 88 | 88 | new[] { shape ?? new TensorShape() }, | |
| 89 | - new[] { name }, | ||
| 89 | + shared_name: shared_name, | ||
| 90 | + name: name); | ||
| 91 | + | ||
| 92 | + /// <summary> | ||
| 93 | + /// Creates a queue that dequeues elements in a first-in first-out order. | ||
| 94 | + /// </summary> | ||
| 95 | + /// <param name="capacity"></param> | ||
| 96 | + /// <param name="dtype"></param> | ||
| 97 | + /// <param name="shape"></param> | ||
| 98 | + /// <param name="shared_name"></param> | ||
| 99 | + /// <param name="name"></param> | ||
| 100 | + /// <returns></returns> | ||
| 101 | + public PriorityQueue PriorityQueue(int capacity, | ||
| 102 | + TF_DataType dtype, | ||
| 103 | + TensorShape shape = null, | ||
| 104 | + string shared_name = null, | ||
| 105 | + string name = "priority_queue") | ||
| 106 | + => new PriorityQueue(capacity, | ||
| 107 | + new[] { dtype }, | ||
| 108 | + new[] { shape ?? new TensorShape() }, | ||
| 90 | 109 | shared_name: shared_name, | |
| 91 | 110 | name: name); | |
| 92 | 111 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,66 @@ | |||
| 1 | + using System; | ||
| 2 | + using System.Collections.Generic; | ||
| 3 | + using System.Linq; | ||
| 4 | + using System.Text; | ||
| 5 | + using static Tensorflow.Binding; | ||
| 6 | + | ||
| 7 | + namespace Tensorflow.Queues | ||
| 8 | + { | ||
| 9 | + public class PriorityQueue : QueueBase | ||
| 10 | + { | ||
| 11 | + public PriorityQueue(int capacity, | ||
| 12 | + TF_DataType[] dtypes, | ||
| 13 | + TensorShape[] shapes, | ||
| 14 | + string[] names = null, | ||
| 15 | + string shared_name = null, | ||
| 16 | + string name = "priority_queue") | ||
| 17 | + : base(dtypes: dtypes, shapes: shapes, names: names) | ||
| 18 | + { | ||
| 19 | + _queue_ref = gen_data_flow_ops.priority_queue_v2( | ||
| 20 | + component_types: dtypes, | ||
| 21 | + shapes: shapes, | ||
| 22 | + capacity: capacity, | ||
| 23 | + shared_name: shared_name, | ||
| 24 | + name: name); | ||
| 25 | + | ||
| 26 | + _name = _queue_ref.op.name.Split('/').Last(); | ||
| 27 | + | ||
| 28 | + var dtypes1 = dtypes.ToList(); | ||
| 29 | + dtypes1.Insert(0, TF_DataType.TF_INT64); | ||
| 30 | + _dtypes = dtypes1.ToArray(); | ||
| 31 | + | ||
| 32 | + var shapes1 = shapes.ToList(); | ||
| 33 | + shapes1.Insert(0, new TensorShape()); | ||
| 34 | + _shapes = shapes1.ToArray(); | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + public Operation enqueue_many<T>(long[] indexes, T[] vals, string name = null) | ||
| 38 | + { | ||
| 39 | + return tf_with(ops.name_scope(name, $"{_name}_EnqueueMany", vals), scope => | ||
| 40 | + { | ||
| 41 | + var vals_tensor1 = _check_enqueue_dtypes(indexes); | ||
| 42 | + var vals_tensor2 = _check_enqueue_dtypes(vals); | ||
| 43 | + | ||
| 44 | + var tensors = new List<Tensor>(); | ||
| 45 | + tensors.AddRange(vals_tensor1); | ||
| 46 | + tensors.AddRange(vals_tensor2); | ||
| 47 | + | ||
| 48 | + return gen_data_flow_ops.queue_enqueue_many_v2(_queue_ref, tensors.ToArray(), name: scope); | ||
| 49 | + }); | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + public Tensor[] dequeue(string name = null) | ||
| 53 | + { | ||
| 54 | + Tensor[] ret; | ||
| 55 | + if (name == null) | ||
| 56 | + name = $"{_name}_Dequeue"; | ||
| 57 | + | ||
| 58 | + if (_queue_ref.dtype == TF_DataType.TF_RESOURCE) | ||
| 59 | + ret = gen_data_flow_ops.queue_dequeue_v2(_queue_ref, _dtypes, name: name); | ||
| 60 | + else | ||
| 61 | + ret = gen_data_flow_ops.queue_dequeue(_queue_ref, _dtypes, name: name); | ||
| 62 | + | ||
| 63 | + return ret; | ||
| 64 | + } | ||
| 65 | + } | ||
| 66 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -42,7 +42,7 @@ public Operation enqueue_many<T>(T[] vals, string name = null) | |||
| 42 | 42 | }); | |
| 43 | 43 | } | |
| 44 | 44 | ||
| 45 | - private Tensor[] _check_enqueue_dtypes(object vals) | ||
| 45 | + protected Tensor[] _check_enqueue_dtypes(object vals) | ||
| 46 | 46 | { | |
| 47 | 47 | var tensors = new List<Tensor>(); | |
| 48 | 48 | ||
@@ -56,12 +56,10 @@ private Tensor[] _check_enqueue_dtypes(object vals) | |||
| 56 | 56 | } | |
| 57 | 57 | break; | |
| 58 | 58 | ||
| 59 | - case int[] vals1: | ||
| 60 | - tensors.Add(ops.convert_to_tensor(vals1, dtype: _dtypes[0], name: $"component_0")); | ||
| 61 | - break; | ||
| 62 | - | ||
| 63 | 59 | default: | |
| 64 | - throw new NotImplementedException(""); | ||
| 60 | + var dtype1 = GetType().Name == "PriorityQueue" ? _dtypes[1] : _dtypes[0]; | ||
| 61 | + tensors.Add(ops.convert_to_tensor(vals, dtype: dtype1, name: $"component_0")); | ||
| 62 | + break; | ||
| 65 | 63 | } | |
| 66 | 64 | ||
| 67 | 65 | return tensors.ToArray(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,28 @@ | |||
| 1 | + using System; | ||
| 2 | + using System.Collections.Generic; | ||
| 3 | + using System.Linq; | ||
| 4 | + using System.Text; | ||
| 5 | + | ||
| 6 | + namespace Tensorflow.Queues | ||
| 7 | + { | ||
| 8 | + public class RandomShuffleQueue : QueueBase | ||
| 9 | + { | ||
| 10 | + public RandomShuffleQueue(int capacity, | ||
| 11 | + TF_DataType[] dtypes, | ||
| 12 | + TensorShape[] shapes, | ||
| 13 | + string[] names = null, | ||
| 14 | + string shared_name = null, | ||
| 15 | + string name = "randomshuffle_fifo_queue") | ||
| 16 | + : base(dtypes: dtypes, shapes: shapes, names: names) | ||
| 17 | + { | ||
| 18 | + _queue_ref = gen_data_flow_ops.padding_fifo_queue_v2( | ||
| 19 | + component_types: dtypes, | ||
| 20 | + shapes: shapes, | ||
| 21 | + capacity: capacity, | ||
| 22 | + shared_name: shared_name, | ||
| 23 | + name: name); | ||
| 24 | + | ||
| 25 | + _name = _queue_ref.op.name.Split('/').Last(); | ||
| 26 | + } | ||
| 27 | + } | ||
| 28 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -77,6 +77,22 @@ public static Tensor fifo_queue_v2(TF_DataType[] component_types, TensorShape[] | |||
| 77 | 77 | return _op.output; | |
| 78 | 78 | } | |
| 79 | 79 | ||
| 80 | + public static Tensor priority_queue_v2(TF_DataType[] component_types, TensorShape[] shapes, | ||
| 81 | + int capacity = -1, string container = "", string shared_name = "", | ||
| 82 | + string name = null) | ||
| 83 | + { | ||
| 84 | + var _op = _op_def_lib._apply_op_helper("PriorityQueueV2", name, new | ||
| 85 | + { | ||
| 86 | + component_types, | ||
| 87 | + shapes, | ||
| 88 | + capacity, | ||
| 89 | + container, | ||
| 90 | + shared_name | ||
| 91 | + }); | ||
| 92 | + | ||
| 93 | + return _op.output; | ||
| 94 | + } | ||
| 95 | + | ||
| 80 | 96 | public static Operation queue_enqueue(Tensor handle, Tensor[] components, int timeout_ms = -1, string name = null) | |
| 81 | 97 | { | |
| 82 | 98 | var _op = _op_def_lib._apply_op_helper("QueueEnqueue", name, new | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,11 +10,12 @@ public class ModelBuilder | |||
| 10 | 10 | { | |
| 11 | 11 | ImageResizerBuilder _image_resizer_builder; | |
| 12 | 12 | FasterRCNNFeatureExtractor _feature_extractor; | |
| 13 | - AnchorGeneratorBuilder anchor_generator_builder; | ||
| 13 | + AnchorGeneratorBuilder _anchor_generator_builder; | ||
| 14 | 14 | ||
| 15 | 15 | public ModelBuilder() | |
| 16 | 16 | { | |
| 17 | 17 | _image_resizer_builder = new ImageResizerBuilder(); | |
| 18 | + _anchor_generator_builder = new AnchorGeneratorBuilder(); | ||
| 18 | 19 | } | |
| 19 | 20 | ||
| 20 | 21 | /// <summary> | |
@@ -51,7 +52,7 @@ private FasterRCNNMetaArch _build_faster_rcnn_model(FasterRcnn frcnn_config, boo | |||
| 51 | 52 | inplace_batchnorm_update: frcnn_config.InplaceBatchnormUpdate); | |
| 52 | 53 | ||
| 53 | 54 | var number_of_stages = frcnn_config.NumberOfStages; | |
| 54 | - var first_stage_anchor_generator = anchor_generator_builder.build(frcnn_config.FirstStageAnchorGenerator); | ||
| 55 | + var first_stage_anchor_generator = _anchor_generator_builder.build(frcnn_config.FirstStageAnchorGenerator); | ||
| 55 | 56 | var first_stage_atrous_rate = frcnn_config.FirstStageAtrousRate; | |
| 56 | 57 | ||
| 57 | 58 | return new FasterRCNNMetaArch(new FasterRCNNInitArgs | |
| Back | FazBrowse Home | New Git URL |
0 commit comments