From 0e9aeafad5ab2d080117bd142ba32f205c5c2787 Mon Sep 17 00:00:00 2001 From: Johann Dirry Date: Tue, 23 Jul 2019 18:13:26 +0200 Subject: [PATCH] removing unused namespaces (#301) * removing unused namespaces * implementing Tensor to scalar and scalar to tensor conversions --- src/KerasNET.Core/Core.cs | 5 +- src/KerasNET.Core/IInitializer.cs | 6 +- .../Initializer/BaseInitializer.cs | 8 +- src/KerasNET.Core/Layers/Dense.cs | 4 - src/KerasNET.Core/Layers/ILayer.cs | 6 +- src/KerasNET.Core/Model.cs | 2 - src/TensorFlowNET.Core/APIs/c_api.cs | 3 - src/TensorFlowNET.Core/APIs/keras.layers.cs | 5 - .../APIs/keras.preprocessing.cs | 3 - src/TensorFlowNET.Core/APIs/tf.array.cs | 1 - src/TensorFlowNET.Core/APIs/tf.control.cs | 4 - .../APIs/tf.distributions.cs | 4 - src/TensorFlowNET.Core/APIs/tf.exp.cs | 4 - src/TensorFlowNET.Core/APIs/tf.gradients.cs | 4 - src/TensorFlowNET.Core/APIs/tf.graph.cs | 4 - src/TensorFlowNET.Core/APIs/tf.init.cs | 3 - src/TensorFlowNET.Core/APIs/tf.io.cs | 2 - src/TensorFlowNET.Core/APIs/tf.layers.cs | 3 - src/TensorFlowNET.Core/APIs/tf.linalg.cs | 4 - src/TensorFlowNET.Core/APIs/tf.loss.cs | 4 - src/TensorFlowNET.Core/APIs/tf.math.cs | 4 - src/TensorFlowNET.Core/APIs/tf.nn.cs | 5 - src/TensorFlowNET.Core/APIs/tf.ops.cs | 4 - src/TensorFlowNET.Core/APIs/tf.random.cs | 4 - .../APIs/tf.reduce_logsumexp.cs | 4 - src/TensorFlowNET.Core/APIs/tf.reshape.cs | 4 - src/TensorFlowNET.Core/APIs/tf.summary.cs | 5 - src/TensorFlowNET.Core/APIs/tf.tensor.cs | 8 +- src/TensorFlowNET.Core/APIs/tf.tile.cs | 3 - src/TensorFlowNET.Core/APIs/tf.variable.cs | 2 - .../Attributes/c_api.ops.cs | 2 - src/TensorFlowNET.Core/Buffers/Buffer.cs | 2 - src/TensorFlowNET.Core/Buffers/TF_Buffer.cs | 2 - .../Buffers/c_api.buffer.cs | 2 - src/TensorFlowNET.Core/Clustering/KMeans.cs | 3 - .../_InitializeClustersOpFactory.cs | 3 - .../Preprocessing/VocabularyProcessor.cs | 4 - src/TensorFlowNET.Core/Data/DatasetV1.cs | 6 +- .../Data/DatasetV1Adapter.cs | 6 +- src/TensorFlowNET.Core/Data/DatasetV2.cs | 6 +- src/TensorFlowNET.Core/Eager/Context.cs | 2 - .../Eager/ContextOptions.cs | 2 - src/TensorFlowNET.Core/Eager/Execute.cs | 4 +- src/TensorFlowNET.Core/Eager/Tape.cs | 6 +- src/TensorFlowNET.Core/Eager/c_api.eager.cs | 2 - .../Eager/pywrap_tfe_src.cs | 4 +- .../Estimator/EstimatorV2.cs | 2 - .../Estimator/HyperParams.cs | 5 +- .../Estimator/IEstimator.cs | 6 +- .../Estimator/TrainingExecutor.cs | 7 +- src/TensorFlowNET.Core/Exceptions/KeyError.cs | 2 - .../Exceptions/RuntimeError.cs | 2 - .../Exceptions/TypeError.cs | 2 - .../Exceptions/ValueError.cs | 2 - .../Framework/CompositeTensor.cs | 6 +- .../Framework/IndexedSlices.cs | 4 - .../Framework/Models/ScopedTFFunction.cs | 6 +- .../Framework/Models/ScopedTFGraph.cs | 6 +- .../Models/ScopedTFImportGraphDefOptions.cs | 6 +- .../Models/ScopedTFImportGraphDefResults.cs | 2 - .../Framework/Models/ScopedTFStatus.cs | 6 +- .../Framework/c_api_util.cs | 1 - .../Framework/common_shapes.py.cs | 2 - .../Framework/graph_util_impl.cs | 1 - .../Framework/importer.py.cs | 1 - .../Framework/meta_graph.py.cs | 1 - .../Framework/op_def_registry.py.cs | 3 - .../Framework/random_seed.py.cs | 4 - .../Framework/smart_module.cs | 2 - .../Framework/sparse_tensor.py.cs | 6 +- src/TensorFlowNET.Core/Functions/Function.cs | 2 - .../Functions/TF_Function.cs | 5 +- .../Functions/c_api.function.cs | 2 - .../Gradients/AggregationMethod.cs | 6 +- .../Gradients/RegisterGradient.cs | 2 - .../Gradients/array_grad.cs | 5 +- .../Gradients/c_api.gradient.cs | 2 - .../Gradients/control_flow_grad.py.cs | 2 - .../Gradients/gradients_impl.py.cs | 5 - .../Gradients/gradients_util.cs | 1 - src/TensorFlowNET.Core/Gradients/math_grad.cs | 2 - src/TensorFlowNET.Core/Gradients/nn_grad.cs | 2 - .../ops.gradient_function_mapping.cs | 1 - .../Graphs/DefaultGraphStack.cs | 2 - src/TensorFlowNET.Core/Graphs/FreezeGraph.cs | 4 - .../Graphs/Graph.Control.cs | 3 - src/TensorFlowNET.Core/Graphs/Graph.Export.cs | 5 - .../Graphs/Graph.Gradient.cs.cs | 6 +- src/TensorFlowNET.Core/Graphs/Graph.Import.cs | 4 - .../Graphs/Graph.Operation.cs | 1 - src/TensorFlowNET.Core/Graphs/Graph.cs | 1 - .../Graphs/ImportGraphDefOptions.cs | 2 - .../Graphs/TF_ImportGraphDefResults.cs | 2 - .../Graphs/_ControlDependenciesController.cs | 3 - src/TensorFlowNET.Core/Graphs/c_api.graph.cs | 2 - src/TensorFlowNET.Core/Graphs/graph_io.py.cs | 3 - src/TensorFlowNET.Core/IO/gfile.cs | 2 - src/TensorFlowNET.Core/IPyClass.cs | 4 - src/TensorFlowNET.Core/ITensorOrOperation.cs | 4 - src/TensorFlowNET.Core/Keras/BackendBase.cs | 4 - .../Keras/Engine/InputSpec.cs | 2 - src/TensorFlowNET.Core/Keras/Engine/Model.cs | 6 +- .../Keras/Engine/Network.cs | 2 - .../Keras/Engine/Sequential.cs | 3 - src/TensorFlowNET.Core/Keras/Initializers.cs | 3 - .../Keras/Layers/BatchNormalization.cs | 2 - src/TensorFlowNET.Core/Keras/Layers/Conv.cs | 1 - src/TensorFlowNET.Core/Keras/Layers/Conv2D.cs | 3 - src/TensorFlowNET.Core/Keras/Layers/Dense.cs | 1 - .../Keras/Layers/Embedding.cs | 4 - .../Keras/Layers/IPoolFunction.cs | 6 +- .../Keras/Layers/InputLayer.cs | 2 - src/TensorFlowNET.Core/Keras/Layers/Layer.cs | 1 - .../Keras/Layers/MaxPooling2D.cs | 5 +- src/TensorFlowNET.Core/Keras/Layers/Node.cs | 3 - .../Keras/Layers/Pooling2D.cs | 3 - src/TensorFlowNET.Core/Keras/Preprocessing.cs | 6 +- src/TensorFlowNET.Core/Keras/Sequence.cs | 4 - .../Keras/Utils/base_layer_utils.cs | 2 - .../Keras/Utils/conv_utils.cs | 4 - .../Keras/Utils/generic_utils.cs | 2 - .../Keras/Utils/tf_utils.cs | 2 - src/TensorFlowNET.Core/Keras/backend.cs | 2 - src/TensorFlowNET.Core/Keras/defaultdict.cs | 2 - src/TensorFlowNET.Core/Keras/tf.keras.cs | 5 +- src/TensorFlowNET.Core/Layers/Dense.cs | 5 +- src/TensorFlowNET.Core/Layers/Layer.cs | 2 - .../Operations/Activation/IActivation.cs | 6 +- .../Activation/gen_nn_ops.activations.cs | 4 - .../Operations/BasicRNNCell.cs | 3 - .../Operations/ControlFlows/CondContext.cs | 1 - .../ControlFlows/ControlFlowContext.cs | 2 - .../ControlFlows/ControlFlowState.cs | 4 - .../Operations/ControlFlows/GradLoopState.cs | 2 - .../ControlFlows/IControlFlowContext.cs | 6 +- .../Operations/ControlFlows/WhileContext.cs | 2 - .../Distributions/DistributionEnum.cs | 7 +- .../Distributions/distribution.py.cs | 1 - .../Operations/Distributions/normal.py.cs | 1 - .../Operations/Initializers/GlorotUniform.cs | 4 - .../Operations/Initializers/IInitializer.cs | 4 - .../Operations/Initializers/Ones.cs | 4 - .../Operations/Initializers/RandomUniform.cs | 4 - .../Initializers/TruncatedNormal.cs | 4 - .../Initializers/VarianceScaling.cs | 2 - .../Operations/Initializers/Zeros.cs | 4 - .../Operations/InputList.cs | 2 - .../Operations/LayerRNNCell.cs | 4 - .../Operations/Losses/Reduction.cs | 6 +- .../Operations/Losses/Util.cs | 6 +- .../Operations/Losses/losses_impl.py.cs | 4 +- .../Operations/NnOps/Conv2dParams.cs | 4 - .../Operations/NnOps/Convolution.cs | 3 - .../Operations/NnOps/MaxPoolFunction.cs | 3 - .../Operations/NnOps/_NonAtrousConvolution.cs | 2 - .../Operations/NnOps/_WithSpaceToBatch.cs | 2 - .../Operations/NnOps/gen_nn_ops.cs | 6 - .../Operations/NnOps/rnn.cs | 1 - .../Operations/OpDefLibrary.cs | 5 - .../Operations/Operation.Control.cs | 3 - .../Operations/Operation.Implicit.cs | 2 - .../Operations/Operation.Input.cs | 2 - .../Operations/Operation.Output.cs | 2 - .../Operations/Operation.cs | 2 - .../Operations/OperationDescription.cs | 2 - src/TensorFlowNET.Core/Operations/RNNCell.cs | 2 - .../Operations/TF_AttrMetadata.cs | 6 +- .../Operations/TF_AttrType.cs | 6 +- src/TensorFlowNET.Core/Operations/TF_Input.cs | 2 - .../Operations/TF_Operation.cs | 2 - .../Operations/TF_OperationDescription.cs | 2 - .../Operations/TF_Output.cs | 2 - .../Operations/_UserDeviceSpec.cs | 4 - .../Operations/array_ops.py.cs | 1 - .../Operations/c_api.ops.cs | 2 - .../Operations/check_ops.cs | 3 - .../Operations/confusion_matrix.py.cs | 2 - .../Operations/control_flow_ops.py.cs | 1 - .../Operations/control_flow_util.py.cs | 3 - .../Operations/embedding_ops.cs | 2 - .../Operations/gen_array_ops.cs | 2 - .../Operations/gen_control_flow_ops.py.cs | 5 - .../Operations/gen_data_flow_ops.py.cs | 4 - .../Operations/gen_image_ops.py.cs | 2 - .../Operations/gen_io_ops.py.cs | 4 - .../Operations/gen_logging_ops.cs | 2 - .../Operations/gen_math_ops.cs | 5 - src/TensorFlowNET.Core/Operations/gen_ops.cs | 4 +- .../Operations/gen_random_ops.py.cs | 4 - .../Operations/gen_resource_variable_ops.cs | 4 - src/TensorFlowNET.Core/Operations/math_ops.cs | 1 - .../Operations/nn_impl.py.cs | 3 - src/TensorFlowNET.Core/Operations/nn_ops.cs | 2 - .../Operations/random_ops.py.cs | 3 - .../Operations/resource_variable_ops.cs | 4 - .../Operations/rnn_cell_impl.cs | 6 +- .../Operations/weights_broadcast_ops.cs | 3 - src/TensorFlowNET.Core/Protobuf/IProtoBuf.cs | 6 +- src/TensorFlowNET.Core/Python.cs | 1 - .../Sessions/BaseSession.cs | 1 - src/TensorFlowNET.Core/Sessions/FeedDict.cs | 5 +- src/TensorFlowNET.Core/Sessions/FeedItem.cs | 6 +- src/TensorFlowNET.Core/Sessions/Session.cs | 2 - .../Sessions/SessionOptions.cs | 2 - .../Sessions/TF_DeprecatedSession.cs | 3 - .../Sessions/TF_SessionOptions.cs | 5 +- .../Sessions/_ElementFetchMapper.cs | 1 - .../Sessions/_FetchHandler.cs | 1 - .../Sessions/_FetchMapper.cs | 3 - .../Sessions/_ListFetchMapper.cs | 1 - .../Sessions/c_api.session.cs | 2 - .../Sessions/c_api.tf_session_helper.cs | 3 - src/TensorFlowNET.Core/Status/Status.cs | 2 - src/TensorFlowNET.Core/Status/TF_Code.cs | 6 +- src/TensorFlowNET.Core/Status/c_api.status.cs | 2 - .../Summaries/EventFileWriter.cs | 1 - .../Summaries/EventLoggerThread.cs | 3 - .../Summaries/EventsWriter.cs | 3 - .../Summaries/FileWriter.cs | 4 - src/TensorFlowNET.Core/Summaries/Summary.cs | 2 - .../Summaries/SummaryToEventTransformer.cs | 3 - src/TensorFlowNET.Core/Tensors/TF_DataType.cs | 6 +- src/TensorFlowNET.Core/Tensors/TF_Tensor.cs | 2 - .../Tensors/Tensor.Creation.cs | 1297 ++++++++--------- .../Tensors/Tensor.Explicit.cs | 92 ++ .../Tensors/Tensor.Implicit.cs | 62 +- .../Tensors/Tensor.Operators.cs | 27 +- src/TensorFlowNET.Core/Tensors/Tensor.cs | 2 - .../Tensors/TensorBuffer.cs | 6 +- src/TensorFlowNET.Core/Tensors/TensorShape.cs | 5 +- .../Tensors/c_api.tensor.cs | 2 - src/TensorFlowNET.Core/Tensors/constant_op.cs | 2 - src/TensorFlowNET.Core/Tensors/dtypes.cs | 2 - src/TensorFlowNET.Core/Tensors/tensor_util.cs | 2 - src/TensorFlowNET.Core/Tensors/tf.constant.cs | 9 +- src/TensorFlowNET.Core/Train/AdamOptimizer.cs | 1 - src/TensorFlowNET.Core/Train/AutoTrackable.cs | 6 +- .../Checkpointable/CheckpointableBase.cs | 5 +- src/TensorFlowNET.Core/Train/Distribute.cs | 6 +- .../Train/GateGradientType.cs | 6 +- .../Train/GradientDescentOptimizer.cs | 4 - src/TensorFlowNET.Core/Train/Optimizer.cs | 1 - .../Train/Saving/BaseSaverBuilder.cs | 1 - .../Train/Saving/BulkSaverBuilder.cs | 6 +- .../Train/Saving/ISaverBuilder.cs | 4 - .../Train/Saving/ReferenceVariableSaveable.cs | 4 - .../Train/Saving/ResourceVariableSaveable.cs | 4 - .../Train/Saving/SaveSpec.cs | 4 - .../Train/Saving/SaveableObject.cs | 4 - src/TensorFlowNET.Core/Train/Saving/Saver.cs | 1 - .../Train/Saving/checkpoint_management.py.cs | 1 - .../Train/Saving/saveable_object_util.py.cs | 1 - .../Train/Saving/saver.py.cs | 1 - src/TensorFlowNET.Core/Train/SlotCreator.cs | 2 - src/TensorFlowNET.Core/Train/Trackable.cs | 2 - .../Train/VariableAggregationType.cs | 6 +- .../Train/_OptimizableVariable.cs | 7 +- .../Train/gen_training_ops.py.cs | 4 - src/TensorFlowNET.Core/Train/optimizer.py.cs | 3 - src/TensorFlowNET.Core/Train/tf.optimizers.cs | 3 - src/TensorFlowNET.Core/Util/CmdHelper.cs | 4 - .../Variables/PureVariableScope.cs | 2 - .../Variables/RefVariable.Implicit.cs | 6 +- .../Variables/RefVariable.Operators.cs | 3 - .../Variables/RefVariable.cs | 3 - .../Variables/ResourceVariable.cs | 1 - .../Variables/VariableScope.cs | 3 - .../Variables/VariableV1.cs | 3 - .../Variables/_ReuseMode.cs | 6 +- .../Variables/_VariableScopeStore.cs | 2 - .../Variables/_VariableStore.cs | 1 - .../Variables/gen_state_ops.py.cs | 2 - src/TensorFlowNET.Core/Variables/state_ops.cs | 2 - .../Variables/variable_scope.py.cs | 1 - .../Variables/variables.py.cs | 1 - src/TensorFlowNET.Core/WeakKeyDicionary.cs | 4 +- src/TensorFlowNET.Core/ops.GraphKeys.cs | 4 - src/TensorFlowNET.Core/ops._DefaultStack.cs | 1 - src/TensorFlowNET.Core/ops.name_scope.cs | 13 +- src/TensorFlowNET.Core/ops.py.cs | 4 - src/TensorFlowNET.Core/tf.cs | 4 - test/KerasNET.Example/Program.cs | 6 - test/KerasNET.Test/BaseTests.cs | 4 +- test/TensorFlowNET.Examples/BasicEagerApi.cs | 2 - .../BasicModels/KMeansClustering.cs | 4 - .../BasicModels/LinearRegression.cs | 2 - .../BasicModels/LogisticRegression.cs | 3 - .../BasicModels/NaiveBayesClassifier.cs | 2 - .../BasicModels/NearestNeighbor.cs | 2 - .../BasicModels/NeuralNetXor.cs | 2 - .../TensorFlowNET.Examples/BasicOperations.cs | 2 - test/TensorFlowNET.Examples/HelloWorld.cs | 2 - test/TensorFlowNET.Examples/IExample.cs | 3 - .../ImageProcessing/DigitRecognitionCNN.cs | 2 - .../ImageProcessing/DigitRecognitionNN.cs | 2 - .../ImageProcessing/DigitRecognitionRNN.cs | 2 - .../ImageProcessing/ImageBackgroundRemoval.cs | 2 - .../ImageRecognitionInception.cs | 3 - .../ImageProcessing/InceptionArchGoogLeNet.cs | 9 +- .../ImageProcessing/ObjectDetection.cs | 2 - .../ImageProcessing/RetrainImageClassifier.cs | 3 - .../BinaryTextClassification.cs | 2 - .../TextProcessing/CnnTextClassification.cs | 3 - .../TextProcessing/NER/BiLstmCrfNer.cs | 3 - .../TextProcessing/NER/CRF.cs | 3 - .../TextProcessing/NER/LstmCrfNer.cs | 1 - .../TextProcessing/NamedEntityRecognition.cs | 3 - .../TextProcessing/Word2Vec.cs | 1 - .../TextProcessing/cnn_models/CharCnn.cs | 6 +- .../TextProcessing/cnn_models/ITextModel.cs | 7 +- .../TextProcessing/cnn_models/VdCnn.cs | 4 +- .../TextProcessing/cnn_models/WordCnn.cs | 3 - .../Utility/ArrayShuffling.cs | 2 - .../Utility/CoNLLDataset.cs | 5 +- .../Utility/DataSetMnist.cs | 3 - .../Utility/Datasets.cs | 3 - .../Utility/IDataSet.cs | 3 - test/TensorFlowNET.Examples/Utility/MNIST.cs | 3 - .../Utility/PbtxtParser.cs | 2 - test/TensorFlowNET.Examples/Utility/Web.cs | 2 - .../CApiAttributesTestcs.cs | 3 - .../CApiColocationTest.cs | 2 - .../CApiGradientsTest.cs | 4 - test/TensorFlowNET.UnitTest/CApiTest.cs | 4 - test/TensorFlowNET.UnitTest/CSession.cs | 2 - test/TensorFlowNET.UnitTest/ConstantTest.cs | 89 +- test/TensorFlowNET.UnitTest/ConsumersTest.cs | 3 - .../Eager/CApiVariableTest.cs | 2 - .../ExamplesTests/ExamplesTest.cs | 5 +- test/TensorFlowNET.UnitTest/GradientTest.cs | 3 - test/TensorFlowNET.UnitTest/GraphTest.cs | 2 - test/TensorFlowNET.UnitTest/NameScopeTest.cs | 3 - test/TensorFlowNET.UnitTest/OperationsTest.cs | 1 - .../TensorFlowNET.UnitTest/PlaceholderTest.cs | 3 - .../TensorFlowNET.UnitTest/PythonBaseTests.cs | 3 - test/TensorFlowNET.UnitTest/PythonTest.cs | 2 - test/TensorFlowNET.UnitTest/SessionTest.cs | 1 - test/TensorFlowNET.UnitTest/StatusTest.cs | 2 - test/TensorFlowNET.UnitTest/TensorTest.cs | 3 - test/TensorFlowNET.UnitTest/TrainSaverTest.cs | 3 - test/TensorFlowNET.UnitTest/VariableTest.cs | 3 - test/TensorFlowNET.UnitTest/VersionTest.cs | 3 - test/TensorFlowNET.UnitTest/c_test_util.cs | 6 +- .../control_flow_ops_test/CondTestCases.cs | 2 - .../control_flow_ops_test/SwitchTestCase.cs | 3 +- .../WhileContextTestCase.cs | 4 - .../gradients_test/GradientsTest.cs | 1082 +++++++------- .../nn_test/ZeroFractionTest.cs | 2 - .../ops_test/ControlDependenciesTest.cs | 2 - .../ops_test/CreateOpFromTfOperationTest.cs | 2 - .../ops_test/GraphTest.cs | 7 +- 351 files changed, 1511 insertions(+), 2263 deletions(-) create mode 100644 src/TensorFlowNET.Core/Tensors/Tensor.Explicit.cs diff --git a/src/KerasNET.Core/Core.cs b/src/KerasNET.Core/Core.cs index 8adae938..4be5a48e 100644 --- a/src/KerasNET.Core/Core.cs +++ b/src/KerasNET.Core/Core.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Tensorflow; +using Tensorflow; namespace Keras { diff --git a/src/KerasNET.Core/IInitializer.cs b/src/KerasNET.Core/IInitializer.cs index 53cb9112..d69e0d1b 100644 --- a/src/KerasNET.Core/IInitializer.cs +++ b/src/KerasNET.Core/IInitializer.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Keras +namespace Keras { interface IInitializer { diff --git a/src/KerasNET.Core/Initializer/BaseInitializer.cs b/src/KerasNET.Core/Initializer/BaseInitializer.cs index 84a420a7..cd3e473c 100644 --- a/src/KerasNET.Core/Initializer/BaseInitializer.cs +++ b/src/KerasNET.Core/Initializer/BaseInitializer.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Tensorflow; -using Tensorflow.Layers; - -namespace Keras.Initializer +namespace Keras.Initializer { class BaseInitializer : IInitializer { diff --git a/src/KerasNET.Core/Layers/Dense.cs b/src/KerasNET.Core/Layers/Dense.cs index 216de124..a45787ce 100644 --- a/src/KerasNET.Core/Layers/Dense.cs +++ b/src/KerasNET.Core/Layers/Dense.cs @@ -15,12 +15,8 @@ ******************************************************************************/ using System; -using System.Collections.Generic; -using System.Text; -using System.Linq; using Tensorflow; using static Keras.Keras; -using Keras; using NumSharp; using Tensorflow.Operations.Activation; diff --git a/src/KerasNET.Core/Layers/ILayer.cs b/src/KerasNET.Core/Layers/ILayer.cs index 2c033eef..9148ca24 100644 --- a/src/KerasNET.Core/Layers/ILayer.cs +++ b/src/KerasNET.Core/Layers/ILayer.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Tensorflow; -using NumSharp; +using Tensorflow; namespace Keras.Layers { diff --git a/src/KerasNET.Core/Model.cs b/src/KerasNET.Core/Model.cs index e35b67ee..b1e6de57 100644 --- a/src/KerasNET.Core/Model.cs +++ b/src/KerasNET.Core/Model.cs @@ -18,9 +18,7 @@ using Keras.Layers; using NumSharp; using System; using System.Collections.Generic; -using System.Text; using Tensorflow; -using static Keras.Keras; using static Tensorflow.Python; namespace Keras diff --git a/src/TensorFlowNET.Core/APIs/c_api.cs b/src/TensorFlowNET.Core/APIs/c_api.cs index 1595e128..1656edd0 100644 --- a/src/TensorFlowNET.Core/APIs/c_api.cs +++ b/src/TensorFlowNET.Core/APIs/c_api.cs @@ -15,10 +15,7 @@ ******************************************************************************/ using System; -using System.Collections.Generic; -using System.Net; using System.Runtime.InteropServices; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/APIs/keras.layers.cs b/src/TensorFlowNET.Core/APIs/keras.layers.cs index 3a2749f5..aba24115 100644 --- a/src/TensorFlowNET.Core/APIs/keras.layers.cs +++ b/src/TensorFlowNET.Core/APIs/keras.layers.cs @@ -14,12 +14,7 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; using System.Linq; -using System.Text; -using Tensorflow.Keras; -using Tensorflow.Keras.Engine; using Tensorflow.Keras.Layers; namespace Tensorflow diff --git a/src/TensorFlowNET.Core/APIs/keras.preprocessing.cs b/src/TensorFlowNET.Core/APIs/keras.preprocessing.cs index 2be63216..125b26f7 100644 --- a/src/TensorFlowNET.Core/APIs/keras.preprocessing.cs +++ b/src/TensorFlowNET.Core/APIs/keras.preprocessing.cs @@ -14,9 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; using Tensorflow.Keras; using Tensorflow.Keras.Engine; diff --git a/src/TensorFlowNET.Core/APIs/tf.array.cs b/src/TensorFlowNET.Core/APIs/tf.array.cs index 3dfdc3d3..48f16b2b 100644 --- a/src/TensorFlowNET.Core/APIs/tf.array.cs +++ b/src/TensorFlowNET.Core/APIs/tf.array.cs @@ -17,7 +17,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/APIs/tf.control.cs b/src/TensorFlowNET.Core/APIs/tf.control.cs index abe0beb6..ce5da031 100644 --- a/src/TensorFlowNET.Core/APIs/tf.control.cs +++ b/src/TensorFlowNET.Core/APIs/tf.control.cs @@ -14,10 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow { public static partial class tf diff --git a/src/TensorFlowNET.Core/APIs/tf.distributions.cs b/src/TensorFlowNET.Core/APIs/tf.distributions.cs index a1006309..dbf2478c 100644 --- a/src/TensorFlowNET.Core/APIs/tf.distributions.cs +++ b/src/TensorFlowNET.Core/APIs/tf.distributions.cs @@ -14,10 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow { public static partial class tf diff --git a/src/TensorFlowNET.Core/APIs/tf.exp.cs b/src/TensorFlowNET.Core/APIs/tf.exp.cs index 04f04148..8caeb12e 100644 --- a/src/TensorFlowNET.Core/APIs/tf.exp.cs +++ b/src/TensorFlowNET.Core/APIs/tf.exp.cs @@ -14,10 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow { public static partial class tf diff --git a/src/TensorFlowNET.Core/APIs/tf.gradients.cs b/src/TensorFlowNET.Core/APIs/tf.gradients.cs index 6b6b2baf..dcdca7a3 100644 --- a/src/TensorFlowNET.Core/APIs/tf.gradients.cs +++ b/src/TensorFlowNET.Core/APIs/tf.gradients.cs @@ -14,10 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow { public static partial class tf diff --git a/src/TensorFlowNET.Core/APIs/tf.graph.cs b/src/TensorFlowNET.Core/APIs/tf.graph.cs index 0496a5ee..e6e60e32 100644 --- a/src/TensorFlowNET.Core/APIs/tf.graph.cs +++ b/src/TensorFlowNET.Core/APIs/tf.graph.cs @@ -14,10 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow { public static partial class tf diff --git a/src/TensorFlowNET.Core/APIs/tf.init.cs b/src/TensorFlowNET.Core/APIs/tf.init.cs index d053b72d..6809b344 100644 --- a/src/TensorFlowNET.Core/APIs/tf.init.cs +++ b/src/TensorFlowNET.Core/APIs/tf.init.cs @@ -14,9 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; using Tensorflow.Operations.Initializers; namespace Tensorflow diff --git a/src/TensorFlowNET.Core/APIs/tf.io.cs b/src/TensorFlowNET.Core/APIs/tf.io.cs index 7f891d18..618b1ea5 100644 --- a/src/TensorFlowNET.Core/APIs/tf.io.cs +++ b/src/TensorFlowNET.Core/APIs/tf.io.cs @@ -14,9 +14,7 @@ limitations under the License. ******************************************************************************/ -using System; using System.Collections.Generic; -using System.Text; using Tensorflow.IO; namespace Tensorflow diff --git a/src/TensorFlowNET.Core/APIs/tf.layers.cs b/src/TensorFlowNET.Core/APIs/tf.layers.cs index cd9a6cb1..a832adab 100644 --- a/src/TensorFlowNET.Core/APIs/tf.layers.cs +++ b/src/TensorFlowNET.Core/APIs/tf.layers.cs @@ -14,9 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; using Tensorflow.Keras.Layers; using Tensorflow.Operations.Activation; diff --git a/src/TensorFlowNET.Core/APIs/tf.linalg.cs b/src/TensorFlowNET.Core/APIs/tf.linalg.cs index bbe8211c..76a6123a 100644 --- a/src/TensorFlowNET.Core/APIs/tf.linalg.cs +++ b/src/TensorFlowNET.Core/APIs/tf.linalg.cs @@ -14,10 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow { public static partial class tf diff --git a/src/TensorFlowNET.Core/APIs/tf.loss.cs b/src/TensorFlowNET.Core/APIs/tf.loss.cs index 6561ae64..1b1b4445 100644 --- a/src/TensorFlowNET.Core/APIs/tf.loss.cs +++ b/src/TensorFlowNET.Core/APIs/tf.loss.cs @@ -14,10 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow { public static partial class tf diff --git a/src/TensorFlowNET.Core/APIs/tf.math.cs b/src/TensorFlowNET.Core/APIs/tf.math.cs index 0ce19616..8d008973 100644 --- a/src/TensorFlowNET.Core/APIs/tf.math.cs +++ b/src/TensorFlowNET.Core/APIs/tf.math.cs @@ -14,10 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow { public static partial class tf diff --git a/src/TensorFlowNET.Core/APIs/tf.nn.cs b/src/TensorFlowNET.Core/APIs/tf.nn.cs index cb9b0b97..9ec1ef58 100644 --- a/src/TensorFlowNET.Core/APIs/tf.nn.cs +++ b/src/TensorFlowNET.Core/APIs/tf.nn.cs @@ -14,13 +14,8 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using Tensorflow.Operations; using Tensorflow.Operations.Activation; -using Tensorflow.Util; using static Tensorflow.Python; namespace Tensorflow diff --git a/src/TensorFlowNET.Core/APIs/tf.ops.cs b/src/TensorFlowNET.Core/APIs/tf.ops.cs index 5d3e481c..51189bda 100644 --- a/src/TensorFlowNET.Core/APIs/tf.ops.cs +++ b/src/TensorFlowNET.Core/APIs/tf.ops.cs @@ -14,10 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow { public static partial class tf diff --git a/src/TensorFlowNET.Core/APIs/tf.random.cs b/src/TensorFlowNET.Core/APIs/tf.random.cs index 9e7408a5..338542d0 100644 --- a/src/TensorFlowNET.Core/APIs/tf.random.cs +++ b/src/TensorFlowNET.Core/APIs/tf.random.cs @@ -14,10 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow { public static partial class tf diff --git a/src/TensorFlowNET.Core/APIs/tf.reduce_logsumexp.cs b/src/TensorFlowNET.Core/APIs/tf.reduce_logsumexp.cs index 9905e64d..d97dd34b 100644 --- a/src/TensorFlowNET.Core/APIs/tf.reduce_logsumexp.cs +++ b/src/TensorFlowNET.Core/APIs/tf.reduce_logsumexp.cs @@ -14,10 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow { public static partial class tf diff --git a/src/TensorFlowNET.Core/APIs/tf.reshape.cs b/src/TensorFlowNET.Core/APIs/tf.reshape.cs index eb8966f4..fac5271e 100644 --- a/src/TensorFlowNET.Core/APIs/tf.reshape.cs +++ b/src/TensorFlowNET.Core/APIs/tf.reshape.cs @@ -14,10 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow { public static partial class tf diff --git a/src/TensorFlowNET.Core/APIs/tf.summary.cs b/src/TensorFlowNET.Core/APIs/tf.summary.cs index 26a533da..a5d52df4 100644 --- a/src/TensorFlowNET.Core/APIs/tf.summary.cs +++ b/src/TensorFlowNET.Core/APIs/tf.summary.cs @@ -14,11 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; -using Tensorflow.IO; - namespace Tensorflow { public static partial class tf diff --git a/src/TensorFlowNET.Core/APIs/tf.tensor.cs b/src/TensorFlowNET.Core/APIs/tf.tensor.cs index 7acff3d5..e2e46fcf 100644 --- a/src/TensorFlowNET.Core/APIs/tf.tensor.cs +++ b/src/TensorFlowNET.Core/APIs/tf.tensor.cs @@ -14,16 +14,10 @@ limitations under the License. ******************************************************************************/ -using NumSharp; -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow { public static partial class tf { - public static Tensor convert_to_tensor(object value, - string name = null) => ops.convert_to_tensor(value, name: name); + public static Tensor convert_to_tensor(object value, string name = null) => ops.convert_to_tensor(value, name: name); } } diff --git a/src/TensorFlowNET.Core/APIs/tf.tile.cs b/src/TensorFlowNET.Core/APIs/tf.tile.cs index 09fbc119..3001166b 100644 --- a/src/TensorFlowNET.Core/APIs/tf.tile.cs +++ b/src/TensorFlowNET.Core/APIs/tf.tile.cs @@ -15,9 +15,6 @@ ******************************************************************************/ using NumSharp; -using System; -using System.Collections.Generic; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/APIs/tf.variable.cs b/src/TensorFlowNET.Core/APIs/tf.variable.cs index 3e3a110d..6512fd92 100644 --- a/src/TensorFlowNET.Core/APIs/tf.variable.cs +++ b/src/TensorFlowNET.Core/APIs/tf.variable.cs @@ -14,9 +14,7 @@ limitations under the License. ******************************************************************************/ -using System; using System.Collections.Generic; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Attributes/c_api.ops.cs b/src/TensorFlowNET.Core/Attributes/c_api.ops.cs index 7db799dd..77877a43 100644 --- a/src/TensorFlowNET.Core/Attributes/c_api.ops.cs +++ b/src/TensorFlowNET.Core/Attributes/c_api.ops.cs @@ -15,9 +15,7 @@ ******************************************************************************/ using System; -using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Buffers/Buffer.cs b/src/TensorFlowNET.Core/Buffers/Buffer.cs index 3f949a62..0b73265d 100644 --- a/src/TensorFlowNET.Core/Buffers/Buffer.cs +++ b/src/TensorFlowNET.Core/Buffers/Buffer.cs @@ -15,9 +15,7 @@ ******************************************************************************/ using System; -using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Buffers/TF_Buffer.cs b/src/TensorFlowNET.Core/Buffers/TF_Buffer.cs index 71b27a58..7ebdd5b8 100644 --- a/src/TensorFlowNET.Core/Buffers/TF_Buffer.cs +++ b/src/TensorFlowNET.Core/Buffers/TF_Buffer.cs @@ -15,9 +15,7 @@ ******************************************************************************/ using System; -using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Buffers/c_api.buffer.cs b/src/TensorFlowNET.Core/Buffers/c_api.buffer.cs index fddd2686..45d165d5 100644 --- a/src/TensorFlowNET.Core/Buffers/c_api.buffer.cs +++ b/src/TensorFlowNET.Core/Buffers/c_api.buffer.cs @@ -15,9 +15,7 @@ ******************************************************************************/ using System; -using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Clustering/KMeans.cs b/src/TensorFlowNET.Core/Clustering/KMeans.cs index 20cf30a6..1ef948a0 100644 --- a/src/TensorFlowNET.Core/Clustering/KMeans.cs +++ b/src/TensorFlowNET.Core/Clustering/KMeans.cs @@ -15,9 +15,6 @@ ******************************************************************************/ using System; -using System.Collections.Generic; -using System.Text; -using static Tensorflow.Python; namespace Tensorflow.Clustering { diff --git a/src/TensorFlowNET.Core/Clustering/_InitializeClustersOpFactory.cs b/src/TensorFlowNET.Core/Clustering/_InitializeClustersOpFactory.cs index 6748cda8..a6253520 100644 --- a/src/TensorFlowNET.Core/Clustering/_InitializeClustersOpFactory.cs +++ b/src/TensorFlowNET.Core/Clustering/_InitializeClustersOpFactory.cs @@ -14,10 +14,7 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; using System.Linq; -using System.Text; using static Tensorflow.Python; namespace Tensorflow.Clustering diff --git a/src/TensorFlowNET.Core/Contrib/Learn/Preprocessing/VocabularyProcessor.cs b/src/TensorFlowNET.Core/Contrib/Learn/Preprocessing/VocabularyProcessor.cs index d4cc9ddc..024190df 100644 --- a/src/TensorFlowNET.Core/Contrib/Learn/Preprocessing/VocabularyProcessor.cs +++ b/src/TensorFlowNET.Core/Contrib/Learn/Preprocessing/VocabularyProcessor.cs @@ -14,10 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow.Contrib.Learn.Preprocessing { public class VocabularyProcessor diff --git a/src/TensorFlowNET.Core/Data/DatasetV1.cs b/src/TensorFlowNET.Core/Data/DatasetV1.cs index b31edace..8739abd4 100644 --- a/src/TensorFlowNET.Core/Data/DatasetV1.cs +++ b/src/TensorFlowNET.Core/Data/DatasetV1.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Tensorflow.Data +namespace Tensorflow.Data { public class DatasetV1 : DatasetV2 { diff --git a/src/TensorFlowNET.Core/Data/DatasetV1Adapter.cs b/src/TensorFlowNET.Core/Data/DatasetV1Adapter.cs index fe5a9b1a..a3097ef7 100644 --- a/src/TensorFlowNET.Core/Data/DatasetV1Adapter.cs +++ b/src/TensorFlowNET.Core/Data/DatasetV1Adapter.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Tensorflow.Data +namespace Tensorflow.Data { /// /// Wraps a V2 `Dataset` object in the `tf.compat.v1.data.Dataset` API. diff --git a/src/TensorFlowNET.Core/Data/DatasetV2.cs b/src/TensorFlowNET.Core/Data/DatasetV2.cs index f49ceb17..1b0e7c57 100644 --- a/src/TensorFlowNET.Core/Data/DatasetV2.cs +++ b/src/TensorFlowNET.Core/Data/DatasetV2.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Tensorflow.Data +namespace Tensorflow.Data { /// /// Represents a potentially large set of elements. diff --git a/src/TensorFlowNET.Core/Eager/Context.cs b/src/TensorFlowNET.Core/Eager/Context.cs index 5a3b35db..4ee43d35 100644 --- a/src/TensorFlowNET.Core/Eager/Context.cs +++ b/src/TensorFlowNET.Core/Eager/Context.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; namespace Tensorflow.Eager { diff --git a/src/TensorFlowNET.Core/Eager/ContextOptions.cs b/src/TensorFlowNET.Core/Eager/ContextOptions.cs index 46d40bf6..4bffddf6 100644 --- a/src/TensorFlowNET.Core/Eager/ContextOptions.cs +++ b/src/TensorFlowNET.Core/Eager/ContextOptions.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; namespace Tensorflow.Eager { diff --git a/src/TensorFlowNET.Core/Eager/Execute.cs b/src/TensorFlowNET.Core/Eager/Execute.cs index caa2d265..e5a2db2f 100644 --- a/src/TensorFlowNET.Core/Eager/Execute.cs +++ b/src/TensorFlowNET.Core/Eager/Execute.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; +using System.Collections.Generic; namespace Tensorflow.Eager { diff --git a/src/TensorFlowNET.Core/Eager/Tape.cs b/src/TensorFlowNET.Core/Eager/Tape.cs index 6d469370..8975ca94 100644 --- a/src/TensorFlowNET.Core/Eager/Tape.cs +++ b/src/TensorFlowNET.Core/Eager/Tape.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Tensorflow.Eager +namespace Tensorflow.Eager { public class Tape { diff --git a/src/TensorFlowNET.Core/Eager/c_api.eager.cs b/src/TensorFlowNET.Core/Eager/c_api.eager.cs index a6d9c8cd..43f2e41d 100644 --- a/src/TensorFlowNET.Core/Eager/c_api.eager.cs +++ b/src/TensorFlowNET.Core/Eager/c_api.eager.cs @@ -1,7 +1,5 @@ using System; -using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Eager/pywrap_tfe_src.cs b/src/TensorFlowNET.Core/Eager/pywrap_tfe_src.cs index 25acbed1..caf9dc57 100644 --- a/src/TensorFlowNET.Core/Eager/pywrap_tfe_src.cs +++ b/src/TensorFlowNET.Core/Eager/pywrap_tfe_src.cs @@ -1,7 +1,5 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; -using System.Text; namespace Tensorflow.Eager { diff --git a/src/TensorFlowNET.Core/Estimator/EstimatorV2.cs b/src/TensorFlowNET.Core/Estimator/EstimatorV2.cs index 2179cdf7..10c2e16e 100644 --- a/src/TensorFlowNET.Core/Estimator/EstimatorV2.cs +++ b/src/TensorFlowNET.Core/Estimator/EstimatorV2.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; using Tensorflow.Data; namespace Tensorflow.Estimator diff --git a/src/TensorFlowNET.Core/Estimator/HyperParams.cs b/src/TensorFlowNET.Core/Estimator/HyperParams.cs index c1777e44..706f00c6 100644 --- a/src/TensorFlowNET.Core/Estimator/HyperParams.cs +++ b/src/TensorFlowNET.Core/Estimator/HyperParams.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; +using System.IO; namespace Tensorflow.Estimator { diff --git a/src/TensorFlowNET.Core/Estimator/IEstimator.cs b/src/TensorFlowNET.Core/Estimator/IEstimator.cs index 77761960..4443f3c3 100644 --- a/src/TensorFlowNET.Core/Estimator/IEstimator.cs +++ b/src/TensorFlowNET.Core/Estimator/IEstimator.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Tensorflow.Estimator +namespace Tensorflow.Estimator { public interface IEstimator { diff --git a/src/TensorFlowNET.Core/Estimator/TrainingExecutor.cs b/src/TensorFlowNET.Core/Estimator/TrainingExecutor.cs index ca76a920..9e281811 100644 --- a/src/TensorFlowNET.Core/Estimator/TrainingExecutor.cs +++ b/src/TensorFlowNET.Core/Estimator/TrainingExecutor.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; -using static Tensorflow.Python; - -namespace Tensorflow.Estimator +namespace Tensorflow.Estimator { /// /// The executor to run `Estimator` training and evaluation. diff --git a/src/TensorFlowNET.Core/Exceptions/KeyError.cs b/src/TensorFlowNET.Core/Exceptions/KeyError.cs index 0dfa2f97..8cecae76 100644 --- a/src/TensorFlowNET.Core/Exceptions/KeyError.cs +++ b/src/TensorFlowNET.Core/Exceptions/KeyError.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Exceptions/RuntimeError.cs b/src/TensorFlowNET.Core/Exceptions/RuntimeError.cs index 71fd773c..09a02a4a 100644 --- a/src/TensorFlowNET.Core/Exceptions/RuntimeError.cs +++ b/src/TensorFlowNET.Core/Exceptions/RuntimeError.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Exceptions/TypeError.cs b/src/TensorFlowNET.Core/Exceptions/TypeError.cs index 71087f8e..a4c37988 100644 --- a/src/TensorFlowNET.Core/Exceptions/TypeError.cs +++ b/src/TensorFlowNET.Core/Exceptions/TypeError.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Exceptions/ValueError.cs b/src/TensorFlowNET.Core/Exceptions/ValueError.cs index 92955d27..825d27a1 100644 --- a/src/TensorFlowNET.Core/Exceptions/ValueError.cs +++ b/src/TensorFlowNET.Core/Exceptions/ValueError.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Framework/CompositeTensor.cs b/src/TensorFlowNET.Core/Framework/CompositeTensor.cs index eac74580..8a942e5a 100644 --- a/src/TensorFlowNET.Core/Framework/CompositeTensor.cs +++ b/src/TensorFlowNET.Core/Framework/CompositeTensor.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Tensorflow.Framework +namespace Tensorflow.Framework { /// /// Abstract base class for Tensor-like objects that are composed from Tensors. diff --git a/src/TensorFlowNET.Core/Framework/IndexedSlices.cs b/src/TensorFlowNET.Core/Framework/IndexedSlices.cs index 721ef7ed..24d356fb 100644 --- a/src/TensorFlowNET.Core/Framework/IndexedSlices.cs +++ b/src/TensorFlowNET.Core/Framework/IndexedSlices.cs @@ -14,10 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow.Framework { /// diff --git a/src/TensorFlowNET.Core/Framework/Models/ScopedTFFunction.cs b/src/TensorFlowNET.Core/Framework/Models/ScopedTFFunction.cs index 13e2b178..bce889b6 100644 --- a/src/TensorFlowNET.Core/Framework/Models/ScopedTFFunction.cs +++ b/src/TensorFlowNET.Core/Framework/Models/ScopedTFFunction.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Tensorflow.Framework.Models +namespace Tensorflow.Framework.Models { class ScopedTFFunction { diff --git a/src/TensorFlowNET.Core/Framework/Models/ScopedTFGraph.cs b/src/TensorFlowNET.Core/Framework/Models/ScopedTFGraph.cs index 7433ecd2..badf52a8 100644 --- a/src/TensorFlowNET.Core/Framework/Models/ScopedTFGraph.cs +++ b/src/TensorFlowNET.Core/Framework/Models/ScopedTFGraph.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Tensorflow.Framework.Models +namespace Tensorflow.Framework.Models { public class ScopedTFGraph : Graph { diff --git a/src/TensorFlowNET.Core/Framework/Models/ScopedTFImportGraphDefOptions.cs b/src/TensorFlowNET.Core/Framework/Models/ScopedTFImportGraphDefOptions.cs index 2a3afe77..dc3955b2 100644 --- a/src/TensorFlowNET.Core/Framework/Models/ScopedTFImportGraphDefOptions.cs +++ b/src/TensorFlowNET.Core/Framework/Models/ScopedTFImportGraphDefOptions.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Tensorflow.Framework.Models +namespace Tensorflow.Framework.Models { public class ScopedTFImportGraphDefOptions : ImportGraphDefOptions { diff --git a/src/TensorFlowNET.Core/Framework/Models/ScopedTFImportGraphDefResults.cs b/src/TensorFlowNET.Core/Framework/Models/ScopedTFImportGraphDefResults.cs index 55ebf08d..fde7d2bb 100644 --- a/src/TensorFlowNET.Core/Framework/Models/ScopedTFImportGraphDefResults.cs +++ b/src/TensorFlowNET.Core/Framework/Models/ScopedTFImportGraphDefResults.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; namespace Tensorflow.Framework.Models { diff --git a/src/TensorFlowNET.Core/Framework/Models/ScopedTFStatus.cs b/src/TensorFlowNET.Core/Framework/Models/ScopedTFStatus.cs index 8af11ffc..068cfbee 100644 --- a/src/TensorFlowNET.Core/Framework/Models/ScopedTFStatus.cs +++ b/src/TensorFlowNET.Core/Framework/Models/ScopedTFStatus.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Tensorflow.Framework.Models +namespace Tensorflow.Framework.Models { public class ScopedTFStatus : Status { diff --git a/src/TensorFlowNET.Core/Framework/c_api_util.cs b/src/TensorFlowNET.Core/Framework/c_api_util.cs index 300abf6e..440cbf44 100644 --- a/src/TensorFlowNET.Core/Framework/c_api_util.cs +++ b/src/TensorFlowNET.Core/Framework/c_api_util.cs @@ -19,7 +19,6 @@ using System.Collections.Generic; using System.IO; using System.IO.Compression; using System.Net; -using System.Text; using System.Threading; using System.Threading.Tasks; diff --git a/src/TensorFlowNET.Core/Framework/common_shapes.py.cs b/src/TensorFlowNET.Core/Framework/common_shapes.py.cs index 249a7e14..b067cf95 100644 --- a/src/TensorFlowNET.Core/Framework/common_shapes.py.cs +++ b/src/TensorFlowNET.Core/Framework/common_shapes.py.cs @@ -15,8 +15,6 @@ ******************************************************************************/ using System; -using System.Collections.Generic; -using System.Text; namespace Tensorflow.Framework { diff --git a/src/TensorFlowNET.Core/Framework/graph_util_impl.cs b/src/TensorFlowNET.Core/Framework/graph_util_impl.cs index 7165b779..ad5c61eb 100644 --- a/src/TensorFlowNET.Core/Framework/graph_util_impl.cs +++ b/src/TensorFlowNET.Core/Framework/graph_util_impl.cs @@ -18,7 +18,6 @@ using NumSharp; using System; using System.Collections.Generic; using System.Linq; -using System.Text; using static Tensorflow.Python; namespace Tensorflow diff --git a/src/TensorFlowNET.Core/Framework/importer.py.cs b/src/TensorFlowNET.Core/Framework/importer.py.cs index c957ced5..577d41aa 100644 --- a/src/TensorFlowNET.Core/Framework/importer.py.cs +++ b/src/TensorFlowNET.Core/Framework/importer.py.cs @@ -18,7 +18,6 @@ using Google.Protobuf; using System; using System.Collections.Generic; using System.Linq; -using System.Text; using static Tensorflow.OpDef.Types; using static Tensorflow.Python; diff --git a/src/TensorFlowNET.Core/Framework/meta_graph.py.cs b/src/TensorFlowNET.Core/Framework/meta_graph.py.cs index 447b7835..4a10ba1e 100644 --- a/src/TensorFlowNET.Core/Framework/meta_graph.py.cs +++ b/src/TensorFlowNET.Core/Framework/meta_graph.py.cs @@ -19,7 +19,6 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Text; using Tensorflow.Operations; using static Tensorflow.CollectionDef; using static Tensorflow.MetaGraphDef.Types; diff --git a/src/TensorFlowNET.Core/Framework/op_def_registry.py.cs b/src/TensorFlowNET.Core/Framework/op_def_registry.py.cs index 8e2099cb..9f9b4ad7 100644 --- a/src/TensorFlowNET.Core/Framework/op_def_registry.py.cs +++ b/src/TensorFlowNET.Core/Framework/op_def_registry.py.cs @@ -14,10 +14,7 @@ limitations under the License. ******************************************************************************/ -using System; using System.Collections.Generic; -using System.Text; -using static Tensorflow.OpDef.Types; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Framework/random_seed.py.cs b/src/TensorFlowNET.Core/Framework/random_seed.py.cs index e48d86e5..cf1b9cb6 100644 --- a/src/TensorFlowNET.Core/Framework/random_seed.py.cs +++ b/src/TensorFlowNET.Core/Framework/random_seed.py.cs @@ -14,10 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow { public class random_seed diff --git a/src/TensorFlowNET.Core/Framework/smart_module.cs b/src/TensorFlowNET.Core/Framework/smart_module.cs index b4dacfb5..908acb75 100644 --- a/src/TensorFlowNET.Core/Framework/smart_module.cs +++ b/src/TensorFlowNET.Core/Framework/smart_module.cs @@ -15,8 +15,6 @@ ******************************************************************************/ using System; -using System.Collections.Generic; -using System.Text; namespace Tensorflow.Framework { diff --git a/src/TensorFlowNET.Core/Framework/sparse_tensor.py.cs b/src/TensorFlowNET.Core/Framework/sparse_tensor.py.cs index 718c989b..547d4516 100644 --- a/src/TensorFlowNET.Core/Framework/sparse_tensor.py.cs +++ b/src/TensorFlowNET.Core/Framework/sparse_tensor.py.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Tensorflow.Framework +namespace Tensorflow.Framework { public static class SparseTensor { diff --git a/src/TensorFlowNET.Core/Functions/Function.cs b/src/TensorFlowNET.Core/Functions/Function.cs index f32464b8..81e3567a 100644 --- a/src/TensorFlowNET.Core/Functions/Function.cs +++ b/src/TensorFlowNET.Core/Functions/Function.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Functions/TF_Function.cs b/src/TensorFlowNET.Core/Functions/TF_Function.cs index 03a442ef..a63dedcc 100644 --- a/src/TensorFlowNET.Core/Functions/TF_Function.cs +++ b/src/TensorFlowNET.Core/Functions/TF_Function.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Runtime.InteropServices; -using System.Text; +using System.Runtime.InteropServices; namespace Tensorflow.Functions { diff --git a/src/TensorFlowNET.Core/Functions/c_api.function.cs b/src/TensorFlowNET.Core/Functions/c_api.function.cs index 68d07afc..9fa12efc 100644 --- a/src/TensorFlowNET.Core/Functions/c_api.function.cs +++ b/src/TensorFlowNET.Core/Functions/c_api.function.cs @@ -15,9 +15,7 @@ ******************************************************************************/ using System; -using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Gradients/AggregationMethod.cs b/src/TensorFlowNET.Core/Gradients/AggregationMethod.cs index 99887a49..6d3414f1 100644 --- a/src/TensorFlowNET.Core/Gradients/AggregationMethod.cs +++ b/src/TensorFlowNET.Core/Gradients/AggregationMethod.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Tensorflow +namespace Tensorflow { public class AggregationMethod { diff --git a/src/TensorFlowNET.Core/Gradients/RegisterGradient.cs b/src/TensorFlowNET.Core/Gradients/RegisterGradient.cs index 0d0d5d7a..08a67373 100644 --- a/src/TensorFlowNET.Core/Gradients/RegisterGradient.cs +++ b/src/TensorFlowNET.Core/Gradients/RegisterGradient.cs @@ -15,8 +15,6 @@ ******************************************************************************/ using System; -using System.Collections.Generic; -using System.Text; namespace Tensorflow.Gradients { diff --git a/src/TensorFlowNET.Core/Gradients/array_grad.cs b/src/TensorFlowNET.Core/Gradients/array_grad.cs index 2708bd79..7830b0d5 100644 --- a/src/TensorFlowNET.Core/Gradients/array_grad.cs +++ b/src/TensorFlowNET.Core/Gradients/array_grad.cs @@ -14,12 +14,9 @@ limitations under the License. ******************************************************************************/ -using System; using System.Collections.Generic; using System.Linq; -using System.Text; using Tensorflow.Framework; -using Tensorflow.Operations; using static Tensorflow.Python; namespace Tensorflow.Gradients @@ -99,7 +96,7 @@ namespace Tensorflow.Gradients new Tensor[] { non_neg_concat_dim, tf.constant(0) }, new Tensor[] { tf.constant(1), tf.constant(-1) }); var squeeze_sizes = array_ops.squeeze(slice); - out_grads = gen_array_ops.split(grad, squeeze_sizes, non_neg_concat_dim).ToList(); + out_grads = gen_array_ops.split(grad, squeeze_sizes, (int)non_neg_concat_dim.Data()[0]).ToList(); } else { diff --git a/src/TensorFlowNET.Core/Gradients/c_api.gradient.cs b/src/TensorFlowNET.Core/Gradients/c_api.gradient.cs index 6b4b1d64..c63783e5 100644 --- a/src/TensorFlowNET.Core/Gradients/c_api.gradient.cs +++ b/src/TensorFlowNET.Core/Gradients/c_api.gradient.cs @@ -15,9 +15,7 @@ ******************************************************************************/ using System; -using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Gradients/control_flow_grad.py.cs b/src/TensorFlowNET.Core/Gradients/control_flow_grad.py.cs index fcae93b2..22a73374 100644 --- a/src/TensorFlowNET.Core/Gradients/control_flow_grad.py.cs +++ b/src/TensorFlowNET.Core/Gradients/control_flow_grad.py.cs @@ -15,9 +15,7 @@ ******************************************************************************/ using System; -using System.Collections.Generic; using System.Linq; -using System.Text; using Tensorflow.Operations; namespace Tensorflow.Gradients diff --git a/src/TensorFlowNET.Core/Gradients/gradients_impl.py.cs b/src/TensorFlowNET.Core/Gradients/gradients_impl.py.cs index b0a1d15c..9a486207 100644 --- a/src/TensorFlowNET.Core/Gradients/gradients_impl.py.cs +++ b/src/TensorFlowNET.Core/Gradients/gradients_impl.py.cs @@ -14,12 +14,7 @@ limitations under the License. ******************************************************************************/ -using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading; -using static Tensorflow.Python; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Gradients/gradients_util.cs b/src/TensorFlowNET.Core/Gradients/gradients_util.cs index 6b96a21c..144179d9 100644 --- a/src/TensorFlowNET.Core/Gradients/gradients_util.cs +++ b/src/TensorFlowNET.Core/Gradients/gradients_util.cs @@ -17,7 +17,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; using static Tensorflow.Python; namespace Tensorflow diff --git a/src/TensorFlowNET.Core/Gradients/math_grad.cs b/src/TensorFlowNET.Core/Gradients/math_grad.cs index e5e99862..71ddc02c 100644 --- a/src/TensorFlowNET.Core/Gradients/math_grad.cs +++ b/src/TensorFlowNET.Core/Gradients/math_grad.cs @@ -15,9 +15,7 @@ ******************************************************************************/ using System; -using System.Collections.Generic; using System.Linq; -using System.Text; using static Tensorflow.Python; namespace Tensorflow.Gradients diff --git a/src/TensorFlowNET.Core/Gradients/nn_grad.cs b/src/TensorFlowNET.Core/Gradients/nn_grad.cs index 7df22722..53ee9699 100644 --- a/src/TensorFlowNET.Core/Gradients/nn_grad.cs +++ b/src/TensorFlowNET.Core/Gradients/nn_grad.cs @@ -15,9 +15,7 @@ ******************************************************************************/ using System; -using System.Collections.Generic; using System.Linq; -using System.Text; using Tensorflow.Operations; namespace Tensorflow.Gradients diff --git a/src/TensorFlowNET.Core/Gradients/ops.gradient_function_mapping.cs b/src/TensorFlowNET.Core/Gradients/ops.gradient_function_mapping.cs index ac6cea74..0b624ba1 100644 --- a/src/TensorFlowNET.Core/Gradients/ops.gradient_function_mapping.cs +++ b/src/TensorFlowNET.Core/Gradients/ops.gradient_function_mapping.cs @@ -18,7 +18,6 @@ using System; using System.Collections.Generic; using System.Linq; using System.Reflection; -using System.Text; using Tensorflow.Gradients; namespace Tensorflow diff --git a/src/TensorFlowNET.Core/Graphs/DefaultGraphStack.cs b/src/TensorFlowNET.Core/Graphs/DefaultGraphStack.cs index 5a44c808..9e6f6346 100644 --- a/src/TensorFlowNET.Core/Graphs/DefaultGraphStack.cs +++ b/src/TensorFlowNET.Core/Graphs/DefaultGraphStack.cs @@ -14,10 +14,8 @@ limitations under the License. ******************************************************************************/ -using System; using System.Collections.Generic; using System.Linq; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Graphs/FreezeGraph.cs b/src/TensorFlowNET.Core/Graphs/FreezeGraph.cs index 20556215..49815edb 100644 --- a/src/TensorFlowNET.Core/Graphs/FreezeGraph.cs +++ b/src/TensorFlowNET.Core/Graphs/FreezeGraph.cs @@ -14,10 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow { public class FreezeGraph diff --git a/src/TensorFlowNET.Core/Graphs/Graph.Control.cs b/src/TensorFlowNET.Core/Graphs/Graph.Control.cs index d0e547fa..70057113 100644 --- a/src/TensorFlowNET.Core/Graphs/Graph.Control.cs +++ b/src/TensorFlowNET.Core/Graphs/Graph.Control.cs @@ -14,11 +14,8 @@ limitations under the License. ******************************************************************************/ -using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using Tensorflow.Eager; using Tensorflow.Operations; namespace Tensorflow diff --git a/src/TensorFlowNET.Core/Graphs/Graph.Export.cs b/src/TensorFlowNET.Core/Graphs/Graph.Export.cs index dcde9677..67b93191 100644 --- a/src/TensorFlowNET.Core/Graphs/Graph.Export.cs +++ b/src/TensorFlowNET.Core/Graphs/Graph.Export.cs @@ -14,11 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Runtime.InteropServices; -using System.Text; - namespace Tensorflow { public partial class Graph diff --git a/src/TensorFlowNET.Core/Graphs/Graph.Gradient.cs.cs b/src/TensorFlowNET.Core/Graphs/Graph.Gradient.cs.cs index 92b0657e..91aef2dc 100644 --- a/src/TensorFlowNET.Core/Graphs/Graph.Gradient.cs.cs +++ b/src/TensorFlowNET.Core/Graphs/Graph.Gradient.cs.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Tensorflow +namespace Tensorflow { public partial class Graph { diff --git a/src/TensorFlowNET.Core/Graphs/Graph.Import.cs b/src/TensorFlowNET.Core/Graphs/Graph.Import.cs index 776d115e..958106ee 100644 --- a/src/TensorFlowNET.Core/Graphs/Graph.Import.cs +++ b/src/TensorFlowNET.Core/Graphs/Graph.Import.cs @@ -14,12 +14,8 @@ limitations under the License. ******************************************************************************/ -using Google.Protobuf; -using System; -using System.Collections.Generic; using System.IO; using System.Runtime.InteropServices; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Graphs/Graph.Operation.cs b/src/TensorFlowNET.Core/Graphs/Graph.Operation.cs index c3bd44b9..06b65f03 100644 --- a/src/TensorFlowNET.Core/Graphs/Graph.Operation.cs +++ b/src/TensorFlowNET.Core/Graphs/Graph.Operation.cs @@ -18,7 +18,6 @@ using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Graphs/Graph.cs b/src/TensorFlowNET.Core/Graphs/Graph.cs index dd2f6cb4..82e83df1 100644 --- a/src/TensorFlowNET.Core/Graphs/Graph.cs +++ b/src/TensorFlowNET.Core/Graphs/Graph.cs @@ -18,7 +18,6 @@ using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Graphs/ImportGraphDefOptions.cs b/src/TensorFlowNET.Core/Graphs/ImportGraphDefOptions.cs index 2c1ac0a0..6a0a812a 100644 --- a/src/TensorFlowNET.Core/Graphs/ImportGraphDefOptions.cs +++ b/src/TensorFlowNET.Core/Graphs/ImportGraphDefOptions.cs @@ -15,8 +15,6 @@ ******************************************************************************/ using System; -using System.Collections.Generic; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Graphs/TF_ImportGraphDefResults.cs b/src/TensorFlowNET.Core/Graphs/TF_ImportGraphDefResults.cs index d857f56f..e9ad8474 100644 --- a/src/TensorFlowNET.Core/Graphs/TF_ImportGraphDefResults.cs +++ b/src/TensorFlowNET.Core/Graphs/TF_ImportGraphDefResults.cs @@ -1,7 +1,5 @@ using System; -using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Graphs/_ControlDependenciesController.cs b/src/TensorFlowNET.Core/Graphs/_ControlDependenciesController.cs index b1337717..900a77ec 100644 --- a/src/TensorFlowNET.Core/Graphs/_ControlDependenciesController.cs +++ b/src/TensorFlowNET.Core/Graphs/_ControlDependenciesController.cs @@ -14,10 +14,7 @@ limitations under the License. ******************************************************************************/ -using System; using System.Collections.Generic; -using System.Text; -using Tensorflow.Eager; using Tensorflow.Operations; namespace Tensorflow diff --git a/src/TensorFlowNET.Core/Graphs/c_api.graph.cs b/src/TensorFlowNET.Core/Graphs/c_api.graph.cs index 3bcb3321..05cd5940 100644 --- a/src/TensorFlowNET.Core/Graphs/c_api.graph.cs +++ b/src/TensorFlowNET.Core/Graphs/c_api.graph.cs @@ -15,9 +15,7 @@ ******************************************************************************/ using System; -using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Graphs/graph_io.py.cs b/src/TensorFlowNET.Core/Graphs/graph_io.py.cs index 162e9ee1..2d1a352e 100644 --- a/src/TensorFlowNET.Core/Graphs/graph_io.py.cs +++ b/src/TensorFlowNET.Core/Graphs/graph_io.py.cs @@ -15,10 +15,7 @@ ******************************************************************************/ using Google.Protobuf; -using System; -using System.Collections.Generic; using System.IO; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/IO/gfile.cs b/src/TensorFlowNET.Core/IO/gfile.cs index cadeb3ad..930dd652 100644 --- a/src/TensorFlowNET.Core/IO/gfile.cs +++ b/src/TensorFlowNET.Core/IO/gfile.cs @@ -14,10 +14,8 @@ limitations under the License. ******************************************************************************/ -using System; using System.Collections.Generic; using System.IO; -using System.Text; namespace Tensorflow.IO { diff --git a/src/TensorFlowNET.Core/IPyClass.cs b/src/TensorFlowNET.Core/IPyClass.cs index d89da986..4cde6ce5 100644 --- a/src/TensorFlowNET.Core/IPyClass.cs +++ b/src/TensorFlowNET.Core/IPyClass.cs @@ -14,10 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow { public interface IPyClass diff --git a/src/TensorFlowNET.Core/ITensorOrOperation.cs b/src/TensorFlowNET.Core/ITensorOrOperation.cs index a74291c5..4b35c299 100644 --- a/src/TensorFlowNET.Core/ITensorOrOperation.cs +++ b/src/TensorFlowNET.Core/ITensorOrOperation.cs @@ -14,10 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow { /// diff --git a/src/TensorFlowNET.Core/Keras/BackendBase.cs b/src/TensorFlowNET.Core/Keras/BackendBase.cs index 8bd5dd08..0b553644 100644 --- a/src/TensorFlowNET.Core/Keras/BackendBase.cs +++ b/src/TensorFlowNET.Core/Keras/BackendBase.cs @@ -14,11 +14,7 @@ limitations under the License. ******************************************************************************/ -using NumSharp; using System; -using System.Collections.Generic; -using System.Text; -using Tensorflow; namespace Tensorflow.Keras { diff --git a/src/TensorFlowNET.Core/Keras/Engine/InputSpec.cs b/src/TensorFlowNET.Core/Keras/Engine/InputSpec.cs index 00ae9955..acaf0b78 100644 --- a/src/TensorFlowNET.Core/Keras/Engine/InputSpec.cs +++ b/src/TensorFlowNET.Core/Keras/Engine/InputSpec.cs @@ -14,9 +14,7 @@ limitations under the License. ******************************************************************************/ -using System; using System.Collections.Generic; -using System.Text; namespace Tensorflow.Keras.Engine { diff --git a/src/TensorFlowNET.Core/Keras/Engine/Model.cs b/src/TensorFlowNET.Core/Keras/Engine/Model.cs index 697a1938..d56c49bc 100644 --- a/src/TensorFlowNET.Core/Keras/Engine/Model.cs +++ b/src/TensorFlowNET.Core/Keras/Engine/Model.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Tensorflow.Keras.Engine +namespace Tensorflow.Keras.Engine { public class Model : Network { diff --git a/src/TensorFlowNET.Core/Keras/Engine/Network.cs b/src/TensorFlowNET.Core/Keras/Engine/Network.cs index f384c289..86d03231 100644 --- a/src/TensorFlowNET.Core/Keras/Engine/Network.cs +++ b/src/TensorFlowNET.Core/Keras/Engine/Network.cs @@ -14,9 +14,7 @@ limitations under the License. ******************************************************************************/ -using System; using System.Collections.Generic; -using System.Text; using Tensorflow.Keras.Layers; namespace Tensorflow.Keras.Engine diff --git a/src/TensorFlowNET.Core/Keras/Engine/Sequential.cs b/src/TensorFlowNET.Core/Keras/Engine/Sequential.cs index 4b6a6f28..651961b4 100644 --- a/src/TensorFlowNET.Core/Keras/Engine/Sequential.cs +++ b/src/TensorFlowNET.Core/Keras/Engine/Sequential.cs @@ -14,9 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; using Tensorflow.Keras.Layers; namespace Tensorflow.Keras.Engine diff --git a/src/TensorFlowNET.Core/Keras/Initializers.cs b/src/TensorFlowNET.Core/Keras/Initializers.cs index 66845f78..1a4fe9e4 100644 --- a/src/TensorFlowNET.Core/Keras/Initializers.cs +++ b/src/TensorFlowNET.Core/Keras/Initializers.cs @@ -14,9 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; using Tensorflow.Operations.Initializers; namespace Tensorflow.Keras diff --git a/src/TensorFlowNET.Core/Keras/Layers/BatchNormalization.cs b/src/TensorFlowNET.Core/Keras/Layers/BatchNormalization.cs index 172c28f2..d10b1874 100644 --- a/src/TensorFlowNET.Core/Keras/Layers/BatchNormalization.cs +++ b/src/TensorFlowNET.Core/Keras/Layers/BatchNormalization.cs @@ -15,9 +15,7 @@ ******************************************************************************/ using System; -using System.Collections.Generic; using System.Linq; -using System.Text; using Tensorflow.Keras.Utils; namespace Tensorflow.Keras.Layers diff --git a/src/TensorFlowNET.Core/Keras/Layers/Conv.cs b/src/TensorFlowNET.Core/Keras/Layers/Conv.cs index d691bdf8..f9a8cecb 100644 --- a/src/TensorFlowNET.Core/Keras/Layers/Conv.cs +++ b/src/TensorFlowNET.Core/Keras/Layers/Conv.cs @@ -16,7 +16,6 @@ using System; using System.Collections.Generic; -using System.Text; using Tensorflow.Keras.Engine; using Tensorflow.Keras.Utils; using Tensorflow.Operations; diff --git a/src/TensorFlowNET.Core/Keras/Layers/Conv2D.cs b/src/TensorFlowNET.Core/Keras/Layers/Conv2D.cs index 7314ca7d..8bc83cce 100644 --- a/src/TensorFlowNET.Core/Keras/Layers/Conv2D.cs +++ b/src/TensorFlowNET.Core/Keras/Layers/Conv2D.cs @@ -14,9 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; using Tensorflow.Operations.Activation; namespace Tensorflow.Keras.Layers diff --git a/src/TensorFlowNET.Core/Keras/Layers/Dense.cs b/src/TensorFlowNET.Core/Keras/Layers/Dense.cs index d402431a..c1528034 100644 --- a/src/TensorFlowNET.Core/Keras/Layers/Dense.cs +++ b/src/TensorFlowNET.Core/Keras/Layers/Dense.cs @@ -17,7 +17,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; using Tensorflow.Keras.Engine; using Tensorflow.Operations.Activation; using static Tensorflow.tf; diff --git a/src/TensorFlowNET.Core/Keras/Layers/Embedding.cs b/src/TensorFlowNET.Core/Keras/Layers/Embedding.cs index 18d78192..299f158d 100644 --- a/src/TensorFlowNET.Core/Keras/Layers/Embedding.cs +++ b/src/TensorFlowNET.Core/Keras/Layers/Embedding.cs @@ -14,10 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow.Keras.Layers { public class Embedding : Layer diff --git a/src/TensorFlowNET.Core/Keras/Layers/IPoolFunction.cs b/src/TensorFlowNET.Core/Keras/Layers/IPoolFunction.cs index 07544f10..a1a5350c 100644 --- a/src/TensorFlowNET.Core/Keras/Layers/IPoolFunction.cs +++ b/src/TensorFlowNET.Core/Keras/Layers/IPoolFunction.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Tensorflow +namespace Tensorflow { public interface IPoolFunction { diff --git a/src/TensorFlowNET.Core/Keras/Layers/InputLayer.cs b/src/TensorFlowNET.Core/Keras/Layers/InputLayer.cs index 4f383375..ce029fa7 100644 --- a/src/TensorFlowNET.Core/Keras/Layers/InputLayer.cs +++ b/src/TensorFlowNET.Core/Keras/Layers/InputLayer.cs @@ -15,8 +15,6 @@ ******************************************************************************/ using System; -using System.Collections.Generic; -using System.Text; namespace Tensorflow.Keras.Layers { diff --git a/src/TensorFlowNET.Core/Keras/Layers/Layer.cs b/src/TensorFlowNET.Core/Keras/Layers/Layer.cs index 4ee0b3c4..f380ce78 100644 --- a/src/TensorFlowNET.Core/Keras/Layers/Layer.cs +++ b/src/TensorFlowNET.Core/Keras/Layers/Layer.cs @@ -17,7 +17,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; using Tensorflow.Keras.Engine; using Tensorflow.Keras.Utils; using Tensorflow.Train; diff --git a/src/TensorFlowNET.Core/Keras/Layers/MaxPooling2D.cs b/src/TensorFlowNET.Core/Keras/Layers/MaxPooling2D.cs index bdb577e0..77e78e1c 100644 --- a/src/TensorFlowNET.Core/Keras/Layers/MaxPooling2D.cs +++ b/src/TensorFlowNET.Core/Keras/Layers/MaxPooling2D.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; -using static Tensorflow.tf; +using static Tensorflow.tf; namespace Tensorflow.Keras.Layers { diff --git a/src/TensorFlowNET.Core/Keras/Layers/Node.cs b/src/TensorFlowNET.Core/Keras/Layers/Node.cs index 0621e0d1..a8785c1d 100644 --- a/src/TensorFlowNET.Core/Keras/Layers/Node.cs +++ b/src/TensorFlowNET.Core/Keras/Layers/Node.cs @@ -14,10 +14,7 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; using System.Linq; -using System.Text; namespace Tensorflow.Keras.Layers { diff --git a/src/TensorFlowNET.Core/Keras/Layers/Pooling2D.cs b/src/TensorFlowNET.Core/Keras/Layers/Pooling2D.cs index 2f41684a..9774750a 100644 --- a/src/TensorFlowNET.Core/Keras/Layers/Pooling2D.cs +++ b/src/TensorFlowNET.Core/Keras/Layers/Pooling2D.cs @@ -14,9 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; using Tensorflow.Keras.Engine; using Tensorflow.Keras.Utils; diff --git a/src/TensorFlowNET.Core/Keras/Preprocessing.cs b/src/TensorFlowNET.Core/Keras/Preprocessing.cs index 81148f58..d8ff073d 100644 --- a/src/TensorFlowNET.Core/Keras/Preprocessing.cs +++ b/src/TensorFlowNET.Core/Keras/Preprocessing.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Tensorflow.Keras +namespace Tensorflow.Keras { public class Preprocessing { diff --git a/src/TensorFlowNET.Core/Keras/Sequence.cs b/src/TensorFlowNET.Core/Keras/Sequence.cs index 67d28bfa..c6f88188 100644 --- a/src/TensorFlowNET.Core/Keras/Sequence.cs +++ b/src/TensorFlowNET.Core/Keras/Sequence.cs @@ -16,11 +16,7 @@ using NumSharp; using System; -using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Text.RegularExpressions; -using System.Threading.Tasks; namespace Tensorflow.Keras { diff --git a/src/TensorFlowNET.Core/Keras/Utils/base_layer_utils.cs b/src/TensorFlowNET.Core/Keras/Utils/base_layer_utils.cs index e8d98f29..a34d9ad0 100644 --- a/src/TensorFlowNET.Core/Keras/Utils/base_layer_utils.cs +++ b/src/TensorFlowNET.Core/Keras/Utils/base_layer_utils.cs @@ -17,8 +17,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using static Tensorflow.Python; namespace Tensorflow.Keras.Utils { diff --git a/src/TensorFlowNET.Core/Keras/Utils/conv_utils.cs b/src/TensorFlowNET.Core/Keras/Utils/conv_utils.cs index f88169e0..ba27fb3d 100644 --- a/src/TensorFlowNET.Core/Keras/Utils/conv_utils.cs +++ b/src/TensorFlowNET.Core/Keras/Utils/conv_utils.cs @@ -14,10 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow.Keras.Utils { public class conv_utils diff --git a/src/TensorFlowNET.Core/Keras/Utils/generic_utils.cs b/src/TensorFlowNET.Core/Keras/Utils/generic_utils.cs index ce322de0..1de763a1 100644 --- a/src/TensorFlowNET.Core/Keras/Utils/generic_utils.cs +++ b/src/TensorFlowNET.Core/Keras/Utils/generic_utils.cs @@ -15,9 +15,7 @@ ******************************************************************************/ using System; -using System.Collections.Generic; using System.Linq; -using System.Text; namespace Tensorflow.Keras.Utils { diff --git a/src/TensorFlowNET.Core/Keras/Utils/tf_utils.cs b/src/TensorFlowNET.Core/Keras/Utils/tf_utils.cs index dae5dd63..fc1b80ff 100644 --- a/src/TensorFlowNET.Core/Keras/Utils/tf_utils.cs +++ b/src/TensorFlowNET.Core/Keras/Utils/tf_utils.cs @@ -15,9 +15,7 @@ ******************************************************************************/ using System; -using System.Collections.Generic; using System.Linq; -using System.Text; using Tensorflow.Framework; namespace Tensorflow.Keras.Utils diff --git a/src/TensorFlowNET.Core/Keras/backend.cs b/src/TensorFlowNET.Core/Keras/backend.cs index 8626e126..3760df04 100644 --- a/src/TensorFlowNET.Core/Keras/backend.cs +++ b/src/TensorFlowNET.Core/Keras/backend.cs @@ -16,8 +16,6 @@ using System; using System.Collections.Generic; -using System.Text; -using System.Runtime.CompilerServices; using static Tensorflow.Python; namespace Tensorflow.Keras diff --git a/src/TensorFlowNET.Core/Keras/defaultdict.cs b/src/TensorFlowNET.Core/Keras/defaultdict.cs index c6d1db01..a87a38ca 100644 --- a/src/TensorFlowNET.Core/Keras/defaultdict.cs +++ b/src/TensorFlowNET.Core/Keras/defaultdict.cs @@ -14,8 +14,6 @@ limitations under the License. ******************************************************************************/ -using System.Collections.Generic; - namespace System.Collections.Generic { public class defaultdict : Dictionary where TValue : new() diff --git a/src/TensorFlowNET.Core/Keras/tf.keras.cs b/src/TensorFlowNET.Core/Keras/tf.keras.cs index 73b8e0a0..bf439809 100644 --- a/src/TensorFlowNET.Core/Keras/tf.keras.cs +++ b/src/TensorFlowNET.Core/Keras/tf.keras.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Tensorflow.Keras; +using Tensorflow.Keras; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Layers/Dense.cs b/src/TensorFlowNET.Core/Layers/Dense.cs index e2868877..3edd1e71 100644 --- a/src/TensorFlowNET.Core/Layers/Dense.cs +++ b/src/TensorFlowNET.Core/Layers/Dense.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Tensorflow.Operations.Activation; +using Tensorflow.Operations.Activation; namespace Tensorflow.Layers { diff --git a/src/TensorFlowNET.Core/Layers/Layer.cs b/src/TensorFlowNET.Core/Layers/Layer.cs index bdea58be..57c71e92 100644 --- a/src/TensorFlowNET.Core/Layers/Layer.cs +++ b/src/TensorFlowNET.Core/Layers/Layer.cs @@ -16,8 +16,6 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; using static Tensorflow.Python; namespace Tensorflow.Layers diff --git a/src/TensorFlowNET.Core/Operations/Activation/IActivation.cs b/src/TensorFlowNET.Core/Operations/Activation/IActivation.cs index 8e1bef24..8da698da 100644 --- a/src/TensorFlowNET.Core/Operations/Activation/IActivation.cs +++ b/src/TensorFlowNET.Core/Operations/Activation/IActivation.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Tensorflow.Operations.Activation +namespace Tensorflow.Operations.Activation { public interface IActivation { diff --git a/src/TensorFlowNET.Core/Operations/Activation/gen_nn_ops.activations.cs b/src/TensorFlowNET.Core/Operations/Activation/gen_nn_ops.activations.cs index 06f74da6..80e1c305 100644 --- a/src/TensorFlowNET.Core/Operations/Activation/gen_nn_ops.activations.cs +++ b/src/TensorFlowNET.Core/Operations/Activation/gen_nn_ops.activations.cs @@ -14,10 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow.Operations.Activation { public class relu : IActivation diff --git a/src/TensorFlowNET.Core/Operations/BasicRNNCell.cs b/src/TensorFlowNET.Core/Operations/BasicRNNCell.cs index 61086076..61da061f 100644 --- a/src/TensorFlowNET.Core/Operations/BasicRNNCell.cs +++ b/src/TensorFlowNET.Core/Operations/BasicRNNCell.cs @@ -15,10 +15,7 @@ ******************************************************************************/ using System; -using System.Collections.Generic; -using System.Text; using Tensorflow.Keras.Engine; -using Tensorflow.Operations.Activation; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Operations/ControlFlows/CondContext.cs b/src/TensorFlowNET.Core/Operations/ControlFlows/CondContext.cs index 98d1aa1c..c6b7d24d 100644 --- a/src/TensorFlowNET.Core/Operations/ControlFlows/CondContext.cs +++ b/src/TensorFlowNET.Core/Operations/ControlFlows/CondContext.cs @@ -17,7 +17,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; using Tensorflow.Operations.ControlFlows; using static Tensorflow.Python; diff --git a/src/TensorFlowNET.Core/Operations/ControlFlows/ControlFlowContext.cs b/src/TensorFlowNET.Core/Operations/ControlFlows/ControlFlowContext.cs index c8c52766..d2a1f628 100644 --- a/src/TensorFlowNET.Core/Operations/ControlFlows/ControlFlowContext.cs +++ b/src/TensorFlowNET.Core/Operations/ControlFlows/ControlFlowContext.cs @@ -17,10 +17,8 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; using Tensorflow.Operations.ControlFlows; using static Tensorflow.ControlFlowContextDef; -using static Tensorflow.Python; namespace Tensorflow.Operations { diff --git a/src/TensorFlowNET.Core/Operations/ControlFlows/ControlFlowState.cs b/src/TensorFlowNET.Core/Operations/ControlFlows/ControlFlowState.cs index a5fba585..fd41c045 100644 --- a/src/TensorFlowNET.Core/Operations/ControlFlows/ControlFlowState.cs +++ b/src/TensorFlowNET.Core/Operations/ControlFlows/ControlFlowState.cs @@ -14,10 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow.Operations.ControlFlows { /// diff --git a/src/TensorFlowNET.Core/Operations/ControlFlows/GradLoopState.cs b/src/TensorFlowNET.Core/Operations/ControlFlows/GradLoopState.cs index c8f359c6..a37a6566 100644 --- a/src/TensorFlowNET.Core/Operations/ControlFlows/GradLoopState.cs +++ b/src/TensorFlowNET.Core/Operations/ControlFlows/GradLoopState.cs @@ -16,8 +16,6 @@ using System; using System.Collections; -using System.Collections.Generic; -using System.Text; namespace Tensorflow.Operations.ControlFlows { diff --git a/src/TensorFlowNET.Core/Operations/ControlFlows/IControlFlowContext.cs b/src/TensorFlowNET.Core/Operations/ControlFlows/IControlFlowContext.cs index f9dde8c4..9aa6d28a 100644 --- a/src/TensorFlowNET.Core/Operations/ControlFlows/IControlFlowContext.cs +++ b/src/TensorFlowNET.Core/Operations/ControlFlows/IControlFlowContext.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Tensorflow +namespace Tensorflow { // henon: this was too much trouble. there is no value just cost to use an interface here. //public interface IControlFlowContext diff --git a/src/TensorFlowNET.Core/Operations/ControlFlows/WhileContext.cs b/src/TensorFlowNET.Core/Operations/ControlFlows/WhileContext.cs index 8211e542..69329b21 100644 --- a/src/TensorFlowNET.Core/Operations/ControlFlows/WhileContext.cs +++ b/src/TensorFlowNET.Core/Operations/ControlFlows/WhileContext.cs @@ -15,8 +15,6 @@ ******************************************************************************/ using System; -using System.Collections.Generic; -using System.Text; using Tensorflow.Operations.ControlFlows; using static Tensorflow.Python; diff --git a/src/TensorFlowNET.Core/Operations/Distributions/DistributionEnum.cs b/src/TensorFlowNET.Core/Operations/Distributions/DistributionEnum.cs index 69a62d27..b3a0c414 100644 --- a/src/TensorFlowNET.Core/Operations/Distributions/DistributionEnum.cs +++ b/src/TensorFlowNET.Core/Operations/Distributions/DistributionEnum.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Tensorflow; - -namespace Tensorflow.Operations.Distributions +namespace Tensorflow.Operations.Distributions { public enum DistributionEnum { diff --git a/src/TensorFlowNET.Core/Operations/Distributions/distribution.py.cs b/src/TensorFlowNET.Core/Operations/Distributions/distribution.py.cs index 76d2554a..19a1266b 100644 --- a/src/TensorFlowNET.Core/Operations/Distributions/distribution.py.cs +++ b/src/TensorFlowNET.Core/Operations/Distributions/distribution.py.cs @@ -17,7 +17,6 @@ //Base classes for probability distributions. using System; using System.Collections.Generic; -using System.Text; using static Tensorflow.Python; diff --git a/src/TensorFlowNET.Core/Operations/Distributions/normal.py.cs b/src/TensorFlowNET.Core/Operations/Distributions/normal.py.cs index be0f41d9..2aa15063 100644 --- a/src/TensorFlowNET.Core/Operations/Distributions/normal.py.cs +++ b/src/TensorFlowNET.Core/Operations/Distributions/normal.py.cs @@ -16,7 +16,6 @@ using System; using System.Collections.Generic; -using Tensorflow; using static Tensorflow.Python; namespace Tensorflow diff --git a/src/TensorFlowNET.Core/Operations/Initializers/GlorotUniform.cs b/src/TensorFlowNET.Core/Operations/Initializers/GlorotUniform.cs index 27571707..1a8b8ba9 100644 --- a/src/TensorFlowNET.Core/Operations/Initializers/GlorotUniform.cs +++ b/src/TensorFlowNET.Core/Operations/Initializers/GlorotUniform.cs @@ -14,10 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow.Operations.Initializers { public class GlorotUniform : VarianceScaling diff --git a/src/TensorFlowNET.Core/Operations/Initializers/IInitializer.cs b/src/TensorFlowNET.Core/Operations/Initializers/IInitializer.cs index 6b0bd5d5..4ca6c140 100644 --- a/src/TensorFlowNET.Core/Operations/Initializers/IInitializer.cs +++ b/src/TensorFlowNET.Core/Operations/Initializers/IInitializer.cs @@ -14,10 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow { public interface IInitializer diff --git a/src/TensorFlowNET.Core/Operations/Initializers/Ones.cs b/src/TensorFlowNET.Core/Operations/Initializers/Ones.cs index 9df67731..d91af335 100644 --- a/src/TensorFlowNET.Core/Operations/Initializers/Ones.cs +++ b/src/TensorFlowNET.Core/Operations/Initializers/Ones.cs @@ -14,10 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow.Operations.Initializers { public class Ones : IInitializer diff --git a/src/TensorFlowNET.Core/Operations/Initializers/RandomUniform.cs b/src/TensorFlowNET.Core/Operations/Initializers/RandomUniform.cs index 5f92ef3f..98595edc 100644 --- a/src/TensorFlowNET.Core/Operations/Initializers/RandomUniform.cs +++ b/src/TensorFlowNET.Core/Operations/Initializers/RandomUniform.cs @@ -14,10 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow.Operations.Initializers { public class RandomUniform : IInitializer diff --git a/src/TensorFlowNET.Core/Operations/Initializers/TruncatedNormal.cs b/src/TensorFlowNET.Core/Operations/Initializers/TruncatedNormal.cs index 7a20fd5b..0611c0e9 100644 --- a/src/TensorFlowNET.Core/Operations/Initializers/TruncatedNormal.cs +++ b/src/TensorFlowNET.Core/Operations/Initializers/TruncatedNormal.cs @@ -14,10 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow.Operations.Initializers { public class TruncatedNormal : IInitializer diff --git a/src/TensorFlowNET.Core/Operations/Initializers/VarianceScaling.cs b/src/TensorFlowNET.Core/Operations/Initializers/VarianceScaling.cs index 3bc45ab5..e88033b5 100644 --- a/src/TensorFlowNET.Core/Operations/Initializers/VarianceScaling.cs +++ b/src/TensorFlowNET.Core/Operations/Initializers/VarianceScaling.cs @@ -15,9 +15,7 @@ ******************************************************************************/ using System; -using System.Collections.Generic; using System.Linq; -using System.Text; namespace Tensorflow.Operations.Initializers { diff --git a/src/TensorFlowNET.Core/Operations/Initializers/Zeros.cs b/src/TensorFlowNET.Core/Operations/Initializers/Zeros.cs index b4eeea38..b9d4f746 100644 --- a/src/TensorFlowNET.Core/Operations/Initializers/Zeros.cs +++ b/src/TensorFlowNET.Core/Operations/Initializers/Zeros.cs @@ -14,10 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow.Operations.Initializers { public class Zeros : IInitializer diff --git a/src/TensorFlowNET.Core/Operations/InputList.cs b/src/TensorFlowNET.Core/Operations/InputList.cs index 2857b162..40c897c5 100644 --- a/src/TensorFlowNET.Core/Operations/InputList.cs +++ b/src/TensorFlowNET.Core/Operations/InputList.cs @@ -14,11 +14,9 @@ limitations under the License. ******************************************************************************/ -using System; using System.Collections; using System.Collections.Generic; using System.Linq; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Operations/LayerRNNCell.cs b/src/TensorFlowNET.Core/Operations/LayerRNNCell.cs index 0f9aa254..ca9c31bb 100644 --- a/src/TensorFlowNET.Core/Operations/LayerRNNCell.cs +++ b/src/TensorFlowNET.Core/Operations/LayerRNNCell.cs @@ -14,10 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow { public class LayerRNNCell : RNNCell diff --git a/src/TensorFlowNET.Core/Operations/Losses/Reduction.cs b/src/TensorFlowNET.Core/Operations/Losses/Reduction.cs index f2421b32..1531848c 100644 --- a/src/TensorFlowNET.Core/Operations/Losses/Reduction.cs +++ b/src/TensorFlowNET.Core/Operations/Losses/Reduction.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Tensorflow +namespace Tensorflow { public class Reduction { diff --git a/src/TensorFlowNET.Core/Operations/Losses/Util.cs b/src/TensorFlowNET.Core/Operations/Losses/Util.cs index 0bd390bd..71b3ed62 100644 --- a/src/TensorFlowNET.Core/Operations/Losses/Util.cs +++ b/src/TensorFlowNET.Core/Operations/Losses/Util.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Tensorflow.Operations.Losses +namespace Tensorflow.Operations.Losses { public class Util { diff --git a/src/TensorFlowNET.Core/Operations/Losses/losses_impl.py.cs b/src/TensorFlowNET.Core/Operations/Losses/losses_impl.py.cs index 238403d2..19ff8b89 100644 --- a/src/TensorFlowNET.Core/Operations/Losses/losses_impl.py.cs +++ b/src/TensorFlowNET.Core/Operations/Losses/losses_impl.py.cs @@ -15,8 +15,6 @@ ******************************************************************************/ using System; -using System.Collections.Generic; -using System.Text; using static Tensorflow.Python; namespace Tensorflow @@ -143,7 +141,7 @@ namespace Tensorflow // Use static rank. var rank_diff = weights_rank - labels_rank; if (rank_diff == 1) - weights = array_ops.squeeze(weights_tensor, new int[] { -1 }); + weights = (int)array_ops.squeeze(weights_tensor, new int[] { -1 }); return (labels, predictions, weights_tensor); } diff --git a/src/TensorFlowNET.Core/Operations/NnOps/Conv2dParams.cs b/src/TensorFlowNET.Core/Operations/NnOps/Conv2dParams.cs index 4decdd4f..dde018df 100644 --- a/src/TensorFlowNET.Core/Operations/NnOps/Conv2dParams.cs +++ b/src/TensorFlowNET.Core/Operations/NnOps/Conv2dParams.cs @@ -14,10 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow.Operations { public class Conv2dParams diff --git a/src/TensorFlowNET.Core/Operations/NnOps/Convolution.cs b/src/TensorFlowNET.Core/Operations/NnOps/Convolution.cs index e3467b83..09350300 100644 --- a/src/TensorFlowNET.Core/Operations/NnOps/Convolution.cs +++ b/src/TensorFlowNET.Core/Operations/NnOps/Convolution.cs @@ -14,10 +14,7 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; using System.Linq; -using System.Text; namespace Tensorflow.Operations { diff --git a/src/TensorFlowNET.Core/Operations/NnOps/MaxPoolFunction.cs b/src/TensorFlowNET.Core/Operations/NnOps/MaxPoolFunction.cs index 6dd48c14..9d1e5726 100644 --- a/src/TensorFlowNET.Core/Operations/NnOps/MaxPoolFunction.cs +++ b/src/TensorFlowNET.Core/Operations/NnOps/MaxPoolFunction.cs @@ -14,9 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; using static Tensorflow.Python; namespace Tensorflow.Operations diff --git a/src/TensorFlowNET.Core/Operations/NnOps/_NonAtrousConvolution.cs b/src/TensorFlowNET.Core/Operations/NnOps/_NonAtrousConvolution.cs index 1300e3b8..4719ba90 100644 --- a/src/TensorFlowNET.Core/Operations/NnOps/_NonAtrousConvolution.cs +++ b/src/TensorFlowNET.Core/Operations/NnOps/_NonAtrousConvolution.cs @@ -15,9 +15,7 @@ ******************************************************************************/ using System; -using System.Collections.Generic; using System.Linq; -using System.Text; namespace Tensorflow.Operations { diff --git a/src/TensorFlowNET.Core/Operations/NnOps/_WithSpaceToBatch.cs b/src/TensorFlowNET.Core/Operations/NnOps/_WithSpaceToBatch.cs index d175b746..daca26a9 100644 --- a/src/TensorFlowNET.Core/Operations/NnOps/_WithSpaceToBatch.cs +++ b/src/TensorFlowNET.Core/Operations/NnOps/_WithSpaceToBatch.cs @@ -15,9 +15,7 @@ ******************************************************************************/ using System; -using System.Collections.Generic; using System.Linq; -using System.Text; namespace Tensorflow.Operations { diff --git a/src/TensorFlowNET.Core/Operations/NnOps/gen_nn_ops.cs b/src/TensorFlowNET.Core/Operations/NnOps/gen_nn_ops.cs index 9244ccff..6c31eb62 100644 --- a/src/TensorFlowNET.Core/Operations/NnOps/gen_nn_ops.cs +++ b/src/TensorFlowNET.Core/Operations/NnOps/gen_nn_ops.cs @@ -14,12 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Tensorflow.Operations.Activation; - namespace Tensorflow.Operations { public class gen_nn_ops diff --git a/src/TensorFlowNET.Core/Operations/NnOps/rnn.cs b/src/TensorFlowNET.Core/Operations/NnOps/rnn.cs index 5f94a0fb..79d1df89 100644 --- a/src/TensorFlowNET.Core/Operations/NnOps/rnn.cs +++ b/src/TensorFlowNET.Core/Operations/NnOps/rnn.cs @@ -16,7 +16,6 @@ using System; using System.Collections.Generic; -using System.Text; using System.Linq; using static Tensorflow.Python; using Tensorflow.Util; diff --git a/src/TensorFlowNET.Core/Operations/OpDefLibrary.cs b/src/TensorFlowNET.Core/Operations/OpDefLibrary.cs index 2e5ec897..033731b0 100644 --- a/src/TensorFlowNET.Core/Operations/OpDefLibrary.cs +++ b/src/TensorFlowNET.Core/Operations/OpDefLibrary.cs @@ -16,12 +16,7 @@ using System; using System.Collections.Generic; -using System.ComponentModel; -using System.Dynamic; -using System.IO; using System.Linq; -using System.Runtime.InteropServices; -using System.Text; using static Tensorflow.OpDef.Types; using static Tensorflow.Python; diff --git a/src/TensorFlowNET.Core/Operations/Operation.Control.cs b/src/TensorFlowNET.Core/Operations/Operation.Control.cs index 48555bf9..2f61f954 100644 --- a/src/TensorFlowNET.Core/Operations/Operation.Control.cs +++ b/src/TensorFlowNET.Core/Operations/Operation.Control.cs @@ -14,9 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; using Tensorflow.Operations; namespace Tensorflow diff --git a/src/TensorFlowNET.Core/Operations/Operation.Implicit.cs b/src/TensorFlowNET.Core/Operations/Operation.Implicit.cs index 5be78704..1b99dcc8 100644 --- a/src/TensorFlowNET.Core/Operations/Operation.Implicit.cs +++ b/src/TensorFlowNET.Core/Operations/Operation.Implicit.cs @@ -15,8 +15,6 @@ ******************************************************************************/ using System; -using System.Collections.Generic; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Operations/Operation.Input.cs b/src/TensorFlowNET.Core/Operations/Operation.Input.cs index b5dd724d..83e7567f 100644 --- a/src/TensorFlowNET.Core/Operations/Operation.Input.cs +++ b/src/TensorFlowNET.Core/Operations/Operation.Input.cs @@ -15,10 +15,8 @@ ******************************************************************************/ using System; -using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Operations/Operation.Output.cs b/src/TensorFlowNET.Core/Operations/Operation.Output.cs index 2f5da994..cefb76cf 100644 --- a/src/TensorFlowNET.Core/Operations/Operation.Output.cs +++ b/src/TensorFlowNET.Core/Operations/Operation.Output.cs @@ -15,10 +15,8 @@ ******************************************************************************/ using System; -using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Operations/Operation.cs b/src/TensorFlowNET.Core/Operations/Operation.cs index 0baa6228..b673380b 100644 --- a/src/TensorFlowNET.Core/Operations/Operation.cs +++ b/src/TensorFlowNET.Core/Operations/Operation.cs @@ -18,8 +18,6 @@ using Google.Protobuf.Collections; using System; using System.Collections.Generic; using System.Linq; -using System.Runtime.InteropServices; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Operations/OperationDescription.cs b/src/TensorFlowNET.Core/Operations/OperationDescription.cs index 489d6fc7..28df548d 100644 --- a/src/TensorFlowNET.Core/Operations/OperationDescription.cs +++ b/src/TensorFlowNET.Core/Operations/OperationDescription.cs @@ -15,8 +15,6 @@ ******************************************************************************/ using System; -using System.Collections.Generic; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Operations/RNNCell.cs b/src/TensorFlowNET.Core/Operations/RNNCell.cs index 79da7761..3b841087 100644 --- a/src/TensorFlowNET.Core/Operations/RNNCell.cs +++ b/src/TensorFlowNET.Core/Operations/RNNCell.cs @@ -15,8 +15,6 @@ ******************************************************************************/ using System; -using System.Collections.Generic; -using System.Text; using Tensorflow.Util; using static Tensorflow.Python; diff --git a/src/TensorFlowNET.Core/Operations/TF_AttrMetadata.cs b/src/TensorFlowNET.Core/Operations/TF_AttrMetadata.cs index dd73da93..a66ee096 100644 --- a/src/TensorFlowNET.Core/Operations/TF_AttrMetadata.cs +++ b/src/TensorFlowNET.Core/Operations/TF_AttrMetadata.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Tensorflow +namespace Tensorflow { public struct TF_AttrMetadata { diff --git a/src/TensorFlowNET.Core/Operations/TF_AttrType.cs b/src/TensorFlowNET.Core/Operations/TF_AttrType.cs index 8a0dc1dc..aa520e4b 100644 --- a/src/TensorFlowNET.Core/Operations/TF_AttrType.cs +++ b/src/TensorFlowNET.Core/Operations/TF_AttrType.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Tensorflow +namespace Tensorflow { public enum TF_AttrType { diff --git a/src/TensorFlowNET.Core/Operations/TF_Input.cs b/src/TensorFlowNET.Core/Operations/TF_Input.cs index 0d49d0e5..c68cb2db 100644 --- a/src/TensorFlowNET.Core/Operations/TF_Input.cs +++ b/src/TensorFlowNET.Core/Operations/TF_Input.cs @@ -1,7 +1,5 @@ using System; -using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Operations/TF_Operation.cs b/src/TensorFlowNET.Core/Operations/TF_Operation.cs index 6d43bdb2..81a142ed 100644 --- a/src/TensorFlowNET.Core/Operations/TF_Operation.cs +++ b/src/TensorFlowNET.Core/Operations/TF_Operation.cs @@ -1,7 +1,5 @@ using System; -using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Operations/TF_OperationDescription.cs b/src/TensorFlowNET.Core/Operations/TF_OperationDescription.cs index 878d9201..4d0a91d9 100644 --- a/src/TensorFlowNET.Core/Operations/TF_OperationDescription.cs +++ b/src/TensorFlowNET.Core/Operations/TF_OperationDescription.cs @@ -1,7 +1,5 @@ using System; -using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Operations/TF_Output.cs b/src/TensorFlowNET.Core/Operations/TF_Output.cs index 16d0285a..a02daa34 100644 --- a/src/TensorFlowNET.Core/Operations/TF_Output.cs +++ b/src/TensorFlowNET.Core/Operations/TF_Output.cs @@ -1,7 +1,5 @@ using System; -using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Operations/_UserDeviceSpec.cs b/src/TensorFlowNET.Core/Operations/_UserDeviceSpec.cs index e027658b..60940247 100644 --- a/src/TensorFlowNET.Core/Operations/_UserDeviceSpec.cs +++ b/src/TensorFlowNET.Core/Operations/_UserDeviceSpec.cs @@ -14,10 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow { public class StringOrFunction diff --git a/src/TensorFlowNET.Core/Operations/array_ops.py.cs b/src/TensorFlowNET.Core/Operations/array_ops.py.cs index 53afc40c..98b36bc6 100644 --- a/src/TensorFlowNET.Core/Operations/array_ops.py.cs +++ b/src/TensorFlowNET.Core/Operations/array_ops.py.cs @@ -17,7 +17,6 @@ using NumSharp; using System; using System.Collections.Generic; -using System.Text; using static Tensorflow.Python; namespace Tensorflow diff --git a/src/TensorFlowNET.Core/Operations/c_api.ops.cs b/src/TensorFlowNET.Core/Operations/c_api.ops.cs index 56f0c5b8..fa24b0ef 100644 --- a/src/TensorFlowNET.Core/Operations/c_api.ops.cs +++ b/src/TensorFlowNET.Core/Operations/c_api.ops.cs @@ -15,9 +15,7 @@ ******************************************************************************/ using System; -using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Operations/check_ops.cs b/src/TensorFlowNET.Core/Operations/check_ops.cs index 37325ad4..d5d76dd3 100644 --- a/src/TensorFlowNET.Core/Operations/check_ops.cs +++ b/src/TensorFlowNET.Core/Operations/check_ops.cs @@ -14,9 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; using static Tensorflow.Python; namespace Tensorflow diff --git a/src/TensorFlowNET.Core/Operations/confusion_matrix.py.cs b/src/TensorFlowNET.Core/Operations/confusion_matrix.py.cs index f7c7b72c..be5ca217 100644 --- a/src/TensorFlowNET.Core/Operations/confusion_matrix.py.cs +++ b/src/TensorFlowNET.Core/Operations/confusion_matrix.py.cs @@ -15,8 +15,6 @@ ******************************************************************************/ using System; -using System.Collections.Generic; -using System.Text; using static Tensorflow.Python; namespace Tensorflow diff --git a/src/TensorFlowNET.Core/Operations/control_flow_ops.py.cs b/src/TensorFlowNET.Core/Operations/control_flow_ops.py.cs index f229a795..39a4538b 100644 --- a/src/TensorFlowNET.Core/Operations/control_flow_ops.py.cs +++ b/src/TensorFlowNET.Core/Operations/control_flow_ops.py.cs @@ -17,7 +17,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; using Tensorflow.Operations; using Tensorflow.Operations.ControlFlows; using util = Tensorflow.control_flow_util; diff --git a/src/TensorFlowNET.Core/Operations/control_flow_util.py.cs b/src/TensorFlowNET.Core/Operations/control_flow_util.py.cs index 70248873..4ae03e42 100644 --- a/src/TensorFlowNET.Core/Operations/control_flow_util.py.cs +++ b/src/TensorFlowNET.Core/Operations/control_flow_util.py.cs @@ -14,9 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; using Tensorflow.Operations; namespace Tensorflow diff --git a/src/TensorFlowNET.Core/Operations/embedding_ops.cs b/src/TensorFlowNET.Core/Operations/embedding_ops.cs index 2a9b5f87..e52107dc 100644 --- a/src/TensorFlowNET.Core/Operations/embedding_ops.cs +++ b/src/TensorFlowNET.Core/Operations/embedding_ops.cs @@ -15,8 +15,6 @@ ******************************************************************************/ using System; -using System.Collections.Generic; -using System.Text; using static Tensorflow.Python; namespace Tensorflow diff --git a/src/TensorFlowNET.Core/Operations/gen_array_ops.cs b/src/TensorFlowNET.Core/Operations/gen_array_ops.cs index b89462a7..e0d88e65 100644 --- a/src/TensorFlowNET.Core/Operations/gen_array_ops.cs +++ b/src/TensorFlowNET.Core/Operations/gen_array_ops.cs @@ -17,8 +17,6 @@ using NumSharp; using System; using System.Collections.Generic; -using System.IO; -using System.Text; using Tensorflow.Eager; namespace Tensorflow diff --git a/src/TensorFlowNET.Core/Operations/gen_control_flow_ops.py.cs b/src/TensorFlowNET.Core/Operations/gen_control_flow_ops.py.cs index b5508893..580da2b7 100644 --- a/src/TensorFlowNET.Core/Operations/gen_control_flow_ops.py.cs +++ b/src/TensorFlowNET.Core/Operations/gen_control_flow_ops.py.cs @@ -14,11 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; -using static Tensorflow.Python; - namespace Tensorflow { public class gen_control_flow_ops diff --git a/src/TensorFlowNET.Core/Operations/gen_data_flow_ops.py.cs b/src/TensorFlowNET.Core/Operations/gen_data_flow_ops.py.cs index 63006806..17f64a29 100644 --- a/src/TensorFlowNET.Core/Operations/gen_data_flow_ops.py.cs +++ b/src/TensorFlowNET.Core/Operations/gen_data_flow_ops.py.cs @@ -14,10 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow { public class gen_data_flow_ops diff --git a/src/TensorFlowNET.Core/Operations/gen_image_ops.py.cs b/src/TensorFlowNET.Core/Operations/gen_image_ops.py.cs index 15cfb10e..dee089ea 100644 --- a/src/TensorFlowNET.Core/Operations/gen_image_ops.py.cs +++ b/src/TensorFlowNET.Core/Operations/gen_image_ops.py.cs @@ -15,8 +15,6 @@ ******************************************************************************/ using System; -using System.Collections.Generic; -using System.Text; using static Tensorflow.Python; namespace Tensorflow diff --git a/src/TensorFlowNET.Core/Operations/gen_io_ops.py.cs b/src/TensorFlowNET.Core/Operations/gen_io_ops.py.cs index 605bd46b..2a921d93 100644 --- a/src/TensorFlowNET.Core/Operations/gen_io_ops.py.cs +++ b/src/TensorFlowNET.Core/Operations/gen_io_ops.py.cs @@ -14,10 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow { public class gen_io_ops diff --git a/src/TensorFlowNET.Core/Operations/gen_logging_ops.cs b/src/TensorFlowNET.Core/Operations/gen_logging_ops.cs index 24615f99..c076ab3e 100644 --- a/src/TensorFlowNET.Core/Operations/gen_logging_ops.cs +++ b/src/TensorFlowNET.Core/Operations/gen_logging_ops.cs @@ -14,9 +14,7 @@ limitations under the License. ******************************************************************************/ -using System; using System.Collections.Generic; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Operations/gen_math_ops.cs b/src/TensorFlowNET.Core/Operations/gen_math_ops.cs index 82aa75f6..9dab24c2 100644 --- a/src/TensorFlowNET.Core/Operations/gen_math_ops.cs +++ b/src/TensorFlowNET.Core/Operations/gen_math_ops.cs @@ -14,11 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; - namespace Tensorflow { public static class gen_math_ops diff --git a/src/TensorFlowNET.Core/Operations/gen_ops.cs b/src/TensorFlowNET.Core/Operations/gen_ops.cs index d3e120e9..e47002ef 100644 --- a/src/TensorFlowNET.Core/Operations/gen_ops.cs +++ b/src/TensorFlowNET.Core/Operations/gen_ops.cs @@ -1,7 +1,5 @@ -using System; -using System.Linq; +using System.Linq; using System.Collections.Generic; -using System.Text; namespace Tensorflow.Operations { diff --git a/src/TensorFlowNET.Core/Operations/gen_random_ops.py.cs b/src/TensorFlowNET.Core/Operations/gen_random_ops.py.cs index 05faf804..8fe9ba71 100644 --- a/src/TensorFlowNET.Core/Operations/gen_random_ops.py.cs +++ b/src/TensorFlowNET.Core/Operations/gen_random_ops.py.cs @@ -14,10 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow { public class gen_random_ops diff --git a/src/TensorFlowNET.Core/Operations/gen_resource_variable_ops.cs b/src/TensorFlowNET.Core/Operations/gen_resource_variable_ops.cs index 319090e4..304a5b55 100644 --- a/src/TensorFlowNET.Core/Operations/gen_resource_variable_ops.cs +++ b/src/TensorFlowNET.Core/Operations/gen_resource_variable_ops.cs @@ -14,10 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow { public static class gen_resource_variable_ops diff --git a/src/TensorFlowNET.Core/Operations/math_ops.cs b/src/TensorFlowNET.Core/Operations/math_ops.cs index 375da903..bc76bc76 100644 --- a/src/TensorFlowNET.Core/Operations/math_ops.cs +++ b/src/TensorFlowNET.Core/Operations/math_ops.cs @@ -17,7 +17,6 @@ using NumSharp; using System; using System.Collections.Generic; -using System.Text; using Tensorflow.Framework; using static Tensorflow.Python; diff --git a/src/TensorFlowNET.Core/Operations/nn_impl.py.cs b/src/TensorFlowNET.Core/Operations/nn_impl.py.cs index 5bad8f35..7555f1cd 100644 --- a/src/TensorFlowNET.Core/Operations/nn_impl.py.cs +++ b/src/TensorFlowNET.Core/Operations/nn_impl.py.cs @@ -14,9 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; using Tensorflow.Operations; using static Tensorflow.Python; diff --git a/src/TensorFlowNET.Core/Operations/nn_ops.cs b/src/TensorFlowNET.Core/Operations/nn_ops.cs index 492e3ca7..0f7efce3 100644 --- a/src/TensorFlowNET.Core/Operations/nn_ops.cs +++ b/src/TensorFlowNET.Core/Operations/nn_ops.cs @@ -15,9 +15,7 @@ ******************************************************************************/ using System; -using System.Collections.Generic; using System.Linq; -using System.Text; using Tensorflow.Operations; using static Tensorflow.Python; diff --git a/src/TensorFlowNET.Core/Operations/random_ops.py.cs b/src/TensorFlowNET.Core/Operations/random_ops.py.cs index 389e46c9..bbcc5156 100644 --- a/src/TensorFlowNET.Core/Operations/random_ops.py.cs +++ b/src/TensorFlowNET.Core/Operations/random_ops.py.cs @@ -14,9 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; using static Tensorflow.Python; namespace Tensorflow diff --git a/src/TensorFlowNET.Core/Operations/resource_variable_ops.cs b/src/TensorFlowNET.Core/Operations/resource_variable_ops.cs index 9dce8407..416e88b4 100644 --- a/src/TensorFlowNET.Core/Operations/resource_variable_ops.cs +++ b/src/TensorFlowNET.Core/Operations/resource_variable_ops.cs @@ -14,10 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow { /// diff --git a/src/TensorFlowNET.Core/Operations/rnn_cell_impl.cs b/src/TensorFlowNET.Core/Operations/rnn_cell_impl.cs index d0625cc9..72f4b866 100644 --- a/src/TensorFlowNET.Core/Operations/rnn_cell_impl.cs +++ b/src/TensorFlowNET.Core/Operations/rnn_cell_impl.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Tensorflow.Operations +namespace Tensorflow.Operations { public class rnn_cell_impl { diff --git a/src/TensorFlowNET.Core/Operations/weights_broadcast_ops.cs b/src/TensorFlowNET.Core/Operations/weights_broadcast_ops.cs index 706d1824..7b889bf8 100644 --- a/src/TensorFlowNET.Core/Operations/weights_broadcast_ops.cs +++ b/src/TensorFlowNET.Core/Operations/weights_broadcast_ops.cs @@ -14,9 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; using static Tensorflow.Python; namespace Tensorflow diff --git a/src/TensorFlowNET.Core/Protobuf/IProtoBuf.cs b/src/TensorFlowNET.Core/Protobuf/IProtoBuf.cs index ce08f5ed..6662a602 100644 --- a/src/TensorFlowNET.Core/Protobuf/IProtoBuf.cs +++ b/src/TensorFlowNET.Core/Protobuf/IProtoBuf.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Tensorflow +namespace Tensorflow { /// /// In order for a object to be serialized to and from MetaGraphDef, diff --git a/src/TensorFlowNET.Core/Python.cs b/src/TensorFlowNET.Core/Python.cs index ce9a5bde..1d205fde 100644 --- a/src/TensorFlowNET.Core/Python.cs +++ b/src/TensorFlowNET.Core/Python.cs @@ -21,7 +21,6 @@ using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Linq; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Sessions/BaseSession.cs b/src/TensorFlowNET.Core/Sessions/BaseSession.cs index 34e0a06a..593c5aba 100644 --- a/src/TensorFlowNET.Core/Sessions/BaseSession.cs +++ b/src/TensorFlowNET.Core/Sessions/BaseSession.cs @@ -20,7 +20,6 @@ using System.Collections; using System.Collections.Generic; using System.Linq; using System.Numerics; -using System.Runtime.InteropServices; using System.Text; namespace Tensorflow diff --git a/src/TensorFlowNET.Core/Sessions/FeedDict.cs b/src/TensorFlowNET.Core/Sessions/FeedDict.cs index 95e51b06..a95b5db1 100644 --- a/src/TensorFlowNET.Core/Sessions/FeedDict.cs +++ b/src/TensorFlowNET.Core/Sessions/FeedDict.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Text; +using System.Collections; namespace Tensorflow.Sessions { diff --git a/src/TensorFlowNET.Core/Sessions/FeedItem.cs b/src/TensorFlowNET.Core/Sessions/FeedItem.cs index 48c1564d..f60f7fb0 100644 --- a/src/TensorFlowNET.Core/Sessions/FeedItem.cs +++ b/src/TensorFlowNET.Core/Sessions/FeedItem.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Tensorflow +namespace Tensorflow { /// /// Feed dictionary item diff --git a/src/TensorFlowNET.Core/Sessions/Session.cs b/src/TensorFlowNET.Core/Sessions/Session.cs index 865e9208..21c4de09 100644 --- a/src/TensorFlowNET.Core/Sessions/Session.cs +++ b/src/TensorFlowNET.Core/Sessions/Session.cs @@ -15,8 +15,6 @@ ******************************************************************************/ using System; -using System.Collections.Generic; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Sessions/SessionOptions.cs b/src/TensorFlowNET.Core/Sessions/SessionOptions.cs index da5b978a..361a48d6 100644 --- a/src/TensorFlowNET.Core/Sessions/SessionOptions.cs +++ b/src/TensorFlowNET.Core/Sessions/SessionOptions.cs @@ -16,9 +16,7 @@ using Google.Protobuf; using System; -using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Sessions/TF_DeprecatedSession.cs b/src/TensorFlowNET.Core/Sessions/TF_DeprecatedSession.cs index 23b9476f..baab71a0 100644 --- a/src/TensorFlowNET.Core/Sessions/TF_DeprecatedSession.cs +++ b/src/TensorFlowNET.Core/Sessions/TF_DeprecatedSession.cs @@ -14,10 +14,7 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Text; namespace Tensorflow.Sessions { diff --git a/src/TensorFlowNET.Core/Sessions/TF_SessionOptions.cs b/src/TensorFlowNET.Core/Sessions/TF_SessionOptions.cs index 628d0ddc..35b27f12 100644 --- a/src/TensorFlowNET.Core/Sessions/TF_SessionOptions.cs +++ b/src/TensorFlowNET.Core/Sessions/TF_SessionOptions.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Runtime.InteropServices; -using System.Text; +using System.Runtime.InteropServices; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Sessions/_ElementFetchMapper.cs b/src/TensorFlowNET.Core/Sessions/_ElementFetchMapper.cs index fb053f2e..ca864ba6 100644 --- a/src/TensorFlowNET.Core/Sessions/_ElementFetchMapper.cs +++ b/src/TensorFlowNET.Core/Sessions/_ElementFetchMapper.cs @@ -17,7 +17,6 @@ using NumSharp; using System; using System.Collections.Generic; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Sessions/_FetchHandler.cs b/src/TensorFlowNET.Core/Sessions/_FetchHandler.cs index 41b54ea5..de135c8e 100644 --- a/src/TensorFlowNET.Core/Sessions/_FetchHandler.cs +++ b/src/TensorFlowNET.Core/Sessions/_FetchHandler.cs @@ -17,7 +17,6 @@ using NumSharp; using System; using System.Collections.Generic; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Sessions/_FetchMapper.cs b/src/TensorFlowNET.Core/Sessions/_FetchMapper.cs index 7ebd8984..69c5c204 100644 --- a/src/TensorFlowNET.Core/Sessions/_FetchMapper.cs +++ b/src/TensorFlowNET.Core/Sessions/_FetchMapper.cs @@ -15,10 +15,7 @@ ******************************************************************************/ using NumSharp; -using System; using System.Collections.Generic; -using System.Linq; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Sessions/_ListFetchMapper.cs b/src/TensorFlowNET.Core/Sessions/_ListFetchMapper.cs index ad54e1a9..f7b25ea5 100644 --- a/src/TensorFlowNET.Core/Sessions/_ListFetchMapper.cs +++ b/src/TensorFlowNET.Core/Sessions/_ListFetchMapper.cs @@ -17,7 +17,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Sessions/c_api.session.cs b/src/TensorFlowNET.Core/Sessions/c_api.session.cs index 95ac835a..3ed60435 100644 --- a/src/TensorFlowNET.Core/Sessions/c_api.session.cs +++ b/src/TensorFlowNET.Core/Sessions/c_api.session.cs @@ -15,9 +15,7 @@ ******************************************************************************/ using System; -using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Sessions/c_api.tf_session_helper.cs b/src/TensorFlowNET.Core/Sessions/c_api.tf_session_helper.cs index da519feb..c40b2a00 100644 --- a/src/TensorFlowNET.Core/Sessions/c_api.tf_session_helper.cs +++ b/src/TensorFlowNET.Core/Sessions/c_api.tf_session_helper.cs @@ -14,10 +14,7 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Status/Status.cs b/src/TensorFlowNET.Core/Status/Status.cs index 5a880bfa..d39a73c7 100644 --- a/src/TensorFlowNET.Core/Status/Status.cs +++ b/src/TensorFlowNET.Core/Status/Status.cs @@ -15,8 +15,6 @@ ******************************************************************************/ using System; -using System.Collections.Generic; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Status/TF_Code.cs b/src/TensorFlowNET.Core/Status/TF_Code.cs index 5e8e3c8d..bb26c370 100644 --- a/src/TensorFlowNET.Core/Status/TF_Code.cs +++ b/src/TensorFlowNET.Core/Status/TF_Code.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Tensorflow +namespace Tensorflow { public enum TF_Code { diff --git a/src/TensorFlowNET.Core/Status/c_api.status.cs b/src/TensorFlowNET.Core/Status/c_api.status.cs index 41aacb53..cfac49d1 100644 --- a/src/TensorFlowNET.Core/Status/c_api.status.cs +++ b/src/TensorFlowNET.Core/Status/c_api.status.cs @@ -15,9 +15,7 @@ ******************************************************************************/ using System; -using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Summaries/EventFileWriter.cs b/src/TensorFlowNET.Core/Summaries/EventFileWriter.cs index 6e7be5e7..4ec6fa24 100644 --- a/src/TensorFlowNET.Core/Summaries/EventFileWriter.cs +++ b/src/TensorFlowNET.Core/Summaries/EventFileWriter.cs @@ -17,7 +17,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.Text; namespace Tensorflow.Summaries { diff --git a/src/TensorFlowNET.Core/Summaries/EventLoggerThread.cs b/src/TensorFlowNET.Core/Summaries/EventLoggerThread.cs index d2eea494..f65019a6 100644 --- a/src/TensorFlowNET.Core/Summaries/EventLoggerThread.cs +++ b/src/TensorFlowNET.Core/Summaries/EventLoggerThread.cs @@ -15,10 +15,7 @@ ******************************************************************************/ using Google.Protobuf; -using System; using System.Collections.Generic; -using System.IO; -using System.Text; using System.Threading; using System.Threading.Tasks; diff --git a/src/TensorFlowNET.Core/Summaries/EventsWriter.cs b/src/TensorFlowNET.Core/Summaries/EventsWriter.cs index 9a1701ce..ae6a94f1 100644 --- a/src/TensorFlowNET.Core/Summaries/EventsWriter.cs +++ b/src/TensorFlowNET.Core/Summaries/EventsWriter.cs @@ -14,10 +14,7 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; using System.IO; -using System.Text; namespace Tensorflow.Summaries { diff --git a/src/TensorFlowNET.Core/Summaries/FileWriter.cs b/src/TensorFlowNET.Core/Summaries/FileWriter.cs index 60949706..1be2747b 100644 --- a/src/TensorFlowNET.Core/Summaries/FileWriter.cs +++ b/src/TensorFlowNET.Core/Summaries/FileWriter.cs @@ -14,10 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow.Summaries { /// diff --git a/src/TensorFlowNET.Core/Summaries/Summary.cs b/src/TensorFlowNET.Core/Summaries/Summary.cs index 00c25992..5a22385f 100644 --- a/src/TensorFlowNET.Core/Summaries/Summary.cs +++ b/src/TensorFlowNET.Core/Summaries/Summary.cs @@ -14,10 +14,8 @@ limitations under the License. ******************************************************************************/ -using System; using System.Collections.Generic; using System.Linq; -using System.Text; using static Tensorflow.Python; namespace Tensorflow.Summaries diff --git a/src/TensorFlowNET.Core/Summaries/SummaryToEventTransformer.cs b/src/TensorFlowNET.Core/Summaries/SummaryToEventTransformer.cs index 6a7368f0..2a395e19 100644 --- a/src/TensorFlowNET.Core/Summaries/SummaryToEventTransformer.cs +++ b/src/TensorFlowNET.Core/Summaries/SummaryToEventTransformer.cs @@ -14,9 +14,6 @@ limitations under the License. ******************************************************************************/ -using Google.Protobuf; -using System; -using System.Collections.Generic; using System.Text; namespace Tensorflow.Summaries diff --git a/src/TensorFlowNET.Core/Tensors/TF_DataType.cs b/src/TensorFlowNET.Core/Tensors/TF_DataType.cs index 308f98f1..97496df1 100644 --- a/src/TensorFlowNET.Core/Tensors/TF_DataType.cs +++ b/src/TensorFlowNET.Core/Tensors/TF_DataType.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Tensorflow +namespace Tensorflow { /// /// TF_DataType holds the type for a scalar value. E.g., one slot in a tensor. diff --git a/src/TensorFlowNET.Core/Tensors/TF_Tensor.cs b/src/TensorFlowNET.Core/Tensors/TF_Tensor.cs index 3332064a..ea80f073 100644 --- a/src/TensorFlowNET.Core/Tensors/TF_Tensor.cs +++ b/src/TensorFlowNET.Core/Tensors/TF_Tensor.cs @@ -1,7 +1,5 @@ using System; -using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Tensors/Tensor.Creation.cs b/src/TensorFlowNET.Core/Tensors/Tensor.Creation.cs index 7ee4edd3..f5ac5f77 100644 --- a/src/TensorFlowNET.Core/Tensors/Tensor.Creation.cs +++ b/src/TensorFlowNET.Core/Tensors/Tensor.Creation.cs @@ -1,649 +1,648 @@ -/***************************************************************************** - Copyright 2018 The TensorFlow.NET Authors. All Rights Reserved. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -******************************************************************************/ - -using NumSharp; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Numerics; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Text; -using static Tensorflow.c_api; - -namespace Tensorflow -{ - public partial class Tensor - { - /// - /// true if unmanaged buffer has been freed. - /// - private bool _deallocator_called => _deallocatorArgs.deallocator_called; - - /// - /// true if the Tensor was created from a managed array - /// - private bool _isPinnedArray => _deallocatorArgs.gc_handle != IntPtr.Zero; - - /// - /// True only if the Tensor object was created in a way that the Tensor object itself allocated memory or pinned a managed object. - /// False if the Tensor was created from a pointer - /// - public bool IsMemoryOwner { get; private set; } - - /// - /// This holds values that are used by the unmanaged deallocator callback - /// - private DeallocatorArgs _deallocatorArgs = new DeallocatorArgs() { gc_handle = IntPtr.Zero }; - - // note: they must be assigned to a static variable in order to work as unmanaged callbacks - static Deallocator _hGlobalDeallocator = FreeHGlobalMemory; - static Deallocator _gcHandleDeallocator = FreeGCHandle; - private static Deallocator _nothingDeallocator = FreeNothing; - - /// - /// Create a Tensor object from an existing TF handle - /// - /// - public Tensor(IntPtr handle) - { - _handle = handle; - IsMemoryOwner = false; - } - - /// - /// Create a new Tensor from the given unmanaged memory pointer (which must be allocated, fixed or pinned by the caller) - /// Note: the caller is responsible for freeing the memory. Calling Dispose on this object will dispose the TensorFlow tensor - /// but not the memory itself! - /// - /// Pointer to unmanaged, fixed or pinned memory which the caller owns - /// Tensor shape - /// TF data type - /// Size of the tensor in memory - public Tensor(IntPtr ptr, long[] shape, TF_DataType dType, int num_bytes) - { - _handle = TF_NewTensor(dType, dims: shape, num_dims: shape.Length, data: ptr, len: (UIntPtr)num_bytes, deallocator: _nothingDeallocator, ref _deallocatorArgs); - IsMemoryOwner = false; - } - -#if _REGEN - %types=["sbyte", "byte", "short", "ushort", "int", "uint", "long", "ulong", "float", "double", "Complex"] - %foreach types% - - /// - /// Create a 1d Tensor from the given linear array and shape - /// - public Tensor(#1[] data, TF_DataType? dType = null) - { - _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(#1)), new long[]{data.Length}, data, Marshal.SizeOf<#1>()); - IsMemoryOwner=true; - } - - /// - /// Create a N-dimensional Tensor from the given array - /// - public Tensor(#1[] data, long[] shape, TF_DataType? dType = null) - { - _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(#1)), shape, data, Marshal.SizeOf<#1>()); - IsMemoryOwner=true; - } - - /// - /// Create a scalar Tensor from the given value - /// - public unsafe Tensor(#1 value, TF_DataType? dType = null) - { - var v = (#1*)Marshal.AllocHGlobal(sizeof(#1)); - *v = value; - _handle = TF_NewTensor(dType ?? dtypes.as_dtype(typeof(#1)), dims:new long[0], num_dims: 0, data: (IntPtr)v, len: (UIntPtr)sizeof(#1), deallocator: _hGlobalDeallocator, ref _deallocatorArgs); - IsMemoryOwner=true; - } - % -#else - - - /// - /// Create a 1d Tensor from the given linear array and shape - /// - public Tensor(sbyte[] data, TF_DataType? dType = null) - { - _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(sbyte)), new long[]{data.Length}, data, Marshal.SizeOf()); - IsMemoryOwner=true; - } - - /// - /// Create a N-dimensional Tensor from the given array - /// - public Tensor(sbyte[] data, long[] shape, TF_DataType? dType = null) - { - _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(sbyte)), shape, data, Marshal.SizeOf()); - IsMemoryOwner=true; - } - - /// - /// Create a scalar Tensor from the given value - /// - public unsafe Tensor(sbyte value, TF_DataType? dType = null) - { - var v = (sbyte*)Marshal.AllocHGlobal(sizeof(sbyte)); - *v = value; - _handle = TF_NewTensor(dType ?? dtypes.as_dtype(typeof(sbyte)), dims:new long[0], num_dims: 0, data: (IntPtr)v, len: (UIntPtr)sizeof(sbyte), deallocator: _hGlobalDeallocator, ref _deallocatorArgs); - IsMemoryOwner=true; - } - - /// - /// Create a 1d Tensor from the given linear array and shape - /// - public Tensor(byte[] data, TF_DataType? dType = null) - { - _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(byte)), new long[]{data.Length}, data, Marshal.SizeOf()); - IsMemoryOwner=true; - } - - /// - /// Create a N-dimensional Tensor from the given array - /// - public Tensor(byte[] data, long[] shape, TF_DataType? dType = null) - { - _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(byte)), shape, data, Marshal.SizeOf()); - IsMemoryOwner=true; - } - - /// - /// Create a scalar Tensor from the given value - /// - public unsafe Tensor(byte value, TF_DataType? dType = null) - { - var v = (byte*)Marshal.AllocHGlobal(sizeof(byte)); - *v = value; - _handle = TF_NewTensor(dType ?? dtypes.as_dtype(typeof(byte)), dims:new long[0], num_dims: 0, data: (IntPtr)v, len: (UIntPtr)sizeof(byte), deallocator: _hGlobalDeallocator, ref _deallocatorArgs); - IsMemoryOwner=true; - } - - /// - /// Create a 1d Tensor from the given linear array and shape - /// - public Tensor(short[] data, TF_DataType? dType = null) - { - _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(short)), new long[]{data.Length}, data, Marshal.SizeOf()); - IsMemoryOwner=true; - } - - /// - /// Create a N-dimensional Tensor from the given array - /// - public Tensor(short[] data, long[] shape, TF_DataType? dType = null) - { - _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(short)), shape, data, Marshal.SizeOf()); - IsMemoryOwner=true; - } - - /// - /// Create a scalar Tensor from the given value - /// - public unsafe Tensor(short value, TF_DataType? dType = null) - { - var v = (short*)Marshal.AllocHGlobal(sizeof(short)); - *v = value; - _handle = TF_NewTensor(dType ?? dtypes.as_dtype(typeof(short)), dims:new long[0], num_dims: 0, data: (IntPtr)v, len: (UIntPtr)sizeof(short), deallocator: _hGlobalDeallocator, ref _deallocatorArgs); - IsMemoryOwner=true; - } - - /// - /// Create a 1d Tensor from the given linear array and shape - /// - public Tensor(ushort[] data, TF_DataType? dType = null) - { - _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(ushort)), new long[]{data.Length}, data, Marshal.SizeOf()); - IsMemoryOwner=true; - } - - /// - /// Create a N-dimensional Tensor from the given array - /// - public Tensor(ushort[] data, long[] shape, TF_DataType? dType = null) - { - _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(ushort)), shape, data, Marshal.SizeOf()); - IsMemoryOwner=true; - } - - /// - /// Create a scalar Tensor from the given value - /// - public unsafe Tensor(ushort value, TF_DataType? dType = null) - { - var v = (ushort*)Marshal.AllocHGlobal(sizeof(ushort)); - *v = value; - _handle = TF_NewTensor(dType ?? dtypes.as_dtype(typeof(ushort)), dims:new long[0], num_dims: 0, data: (IntPtr)v, len: (UIntPtr)sizeof(ushort), deallocator: _hGlobalDeallocator, ref _deallocatorArgs); - IsMemoryOwner=true; - } - - /// - /// Create a 1d Tensor from the given linear array and shape - /// - public Tensor(int[] data, TF_DataType? dType = null) - { - _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(int)), new long[]{data.Length}, data, Marshal.SizeOf()); - IsMemoryOwner=true; - } - - /// - /// Create a N-dimensional Tensor from the given array - /// - public Tensor(int[] data, long[] shape, TF_DataType? dType = null) - { - _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(int)), shape, data, Marshal.SizeOf()); - IsMemoryOwner=true; - } - - /// - /// Create a scalar Tensor from the given value - /// - public unsafe Tensor(int value, TF_DataType? dType = null) - { - var v = (int*)Marshal.AllocHGlobal(sizeof(int)); - *v = value; - _handle = TF_NewTensor(dType ?? dtypes.as_dtype(typeof(int)), dims:new long[0], num_dims: 0, data: (IntPtr)v, len: (UIntPtr)sizeof(int), deallocator: _hGlobalDeallocator, ref _deallocatorArgs); - IsMemoryOwner=true; - } - - /// - /// Create a 1d Tensor from the given linear array and shape - /// - public Tensor(uint[] data, TF_DataType? dType = null) - { - _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(uint)), new long[]{data.Length}, data, Marshal.SizeOf()); - IsMemoryOwner=true; - } - - /// - /// Create a N-dimensional Tensor from the given array - /// - public Tensor(uint[] data, long[] shape, TF_DataType? dType = null) - { - _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(uint)), shape, data, Marshal.SizeOf()); - IsMemoryOwner=true; - } - - /// - /// Create a scalar Tensor from the given value - /// - public unsafe Tensor(uint value, TF_DataType? dType = null) - { - var v = (uint*)Marshal.AllocHGlobal(sizeof(uint)); - *v = value; - _handle = TF_NewTensor(dType ?? dtypes.as_dtype(typeof(uint)), dims:new long[0], num_dims: 0, data: (IntPtr)v, len: (UIntPtr)sizeof(uint), deallocator: _hGlobalDeallocator, ref _deallocatorArgs); - IsMemoryOwner=true; - } - - /// - /// Create a 1d Tensor from the given linear array and shape - /// - public Tensor(long[] data, TF_DataType? dType = null) - { - _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(long)), new long[]{data.Length}, data, Marshal.SizeOf()); - IsMemoryOwner=true; - } - - /// - /// Create a N-dimensional Tensor from the given array - /// - public Tensor(long[] data, long[] shape, TF_DataType? dType = null) - { - _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(long)), shape, data, Marshal.SizeOf()); - IsMemoryOwner=true; - } - - /// - /// Create a scalar Tensor from the given value - /// - public unsafe Tensor(long value, TF_DataType? dType = null) - { - var v = (long*)Marshal.AllocHGlobal(sizeof(long)); - *v = value; - _handle = TF_NewTensor(dType ?? dtypes.as_dtype(typeof(long)), dims:new long[0], num_dims: 0, data: (IntPtr)v, len: (UIntPtr)sizeof(long), deallocator: _hGlobalDeallocator, ref _deallocatorArgs); - IsMemoryOwner=true; - } - - /// - /// Create a 1d Tensor from the given linear array and shape - /// - public Tensor(ulong[] data, TF_DataType? dType = null) - { - _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(ulong)), new long[]{data.Length}, data, Marshal.SizeOf()); - IsMemoryOwner=true; - } - - /// - /// Create a N-dimensional Tensor from the given array - /// - public Tensor(ulong[] data, long[] shape, TF_DataType? dType = null) - { - _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(ulong)), shape, data, Marshal.SizeOf()); - IsMemoryOwner=true; - } - - /// - /// Create a scalar Tensor from the given value - /// - public unsafe Tensor(ulong value, TF_DataType? dType = null) - { - var v = (ulong*)Marshal.AllocHGlobal(sizeof(ulong)); - *v = value; - _handle = TF_NewTensor(dType ?? dtypes.as_dtype(typeof(ulong)), dims:new long[0], num_dims: 0, data: (IntPtr)v, len: (UIntPtr)sizeof(ulong), deallocator: _hGlobalDeallocator, ref _deallocatorArgs); - IsMemoryOwner=true; - } - - /// - /// Create a 1d Tensor from the given linear array and shape - /// - public Tensor(float[] data, TF_DataType? dType = null) - { - _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(float)), new long[]{data.Length}, data, Marshal.SizeOf()); - IsMemoryOwner=true; - } - - /// - /// Create a N-dimensional Tensor from the given array - /// - public Tensor(float[] data, long[] shape, TF_DataType? dType = null) - { - _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(float)), shape, data, Marshal.SizeOf()); - IsMemoryOwner=true; - } - - /// - /// Create a scalar Tensor from the given value - /// - public unsafe Tensor(float value, TF_DataType? dType = null) - { - var v = (float*)Marshal.AllocHGlobal(sizeof(float)); - *v = value; - _handle = TF_NewTensor(dType ?? dtypes.as_dtype(typeof(float)), dims:new long[0], num_dims: 0, data: (IntPtr)v, len: (UIntPtr)sizeof(float), deallocator: _hGlobalDeallocator, ref _deallocatorArgs); - IsMemoryOwner=true; - } - - /// - /// Create a 1d Tensor from the given linear array and shape - /// - public Tensor(double[] data, TF_DataType? dType = null) - { - _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(double)), new long[]{data.Length}, data, Marshal.SizeOf()); - IsMemoryOwner=true; - } - - /// - /// Create a N-dimensional Tensor from the given array - /// - public Tensor(double[] data, long[] shape, TF_DataType? dType = null) - { - _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(double)), shape, data, Marshal.SizeOf()); - IsMemoryOwner=true; - } - - /// - /// Create a scalar Tensor from the given value - /// - public unsafe Tensor(double value, TF_DataType? dType = null) - { - var v = (double*)Marshal.AllocHGlobal(sizeof(double)); - *v = value; - _handle = TF_NewTensor(dType ?? dtypes.as_dtype(typeof(double)), dims:new long[0], num_dims: 0, data: (IntPtr)v, len: (UIntPtr)sizeof(double), deallocator: _hGlobalDeallocator, ref _deallocatorArgs); - IsMemoryOwner=true; - } - - /// - /// Create a 1d Tensor from the given linear array and shape - /// - public Tensor(Complex[] data, TF_DataType? dType = null) - { - _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(Complex)), new long[]{data.Length}, data, Marshal.SizeOf()); - IsMemoryOwner=true; - } - - /// - /// Create a N-dimensional Tensor from the given array - /// - public Tensor(Complex[] data, long[] shape, TF_DataType? dType = null) - { - _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(Complex)), shape, data, Marshal.SizeOf()); - IsMemoryOwner=true; - } - - /// - /// Create a scalar Tensor from the given value - /// - public unsafe Tensor(Complex value, TF_DataType? dType = null) - { - var v = (Complex*)Marshal.AllocHGlobal(sizeof(Complex)); - *v = value; - _handle = TF_NewTensor(dType ?? dtypes.as_dtype(typeof(Complex)), dims:new long[0], num_dims: 0, data: (IntPtr)v, len: (UIntPtr)sizeof(Complex), deallocator: _hGlobalDeallocator, ref _deallocatorArgs); - IsMemoryOwner=true; - } -#endif - - /// - /// Create a string Tensor from the given string - /// - public unsafe Tensor(string str) - { - var buffer = Encoding.UTF8.GetBytes(str); - var size = c_api.TF_StringEncodedSize((UIntPtr)buffer.Length); - var handle = TF_AllocateTensor(TF_DataType.TF_STRING, IntPtr.Zero, 0, (UIntPtr)((ulong)size + 8)); - - IntPtr tensor = c_api.TF_TensorData(handle); - Marshal.WriteInt64(tensor, 0); - fixed (byte* src = &buffer[0]) - c_api.TF_StringEncode(src, (UIntPtr)buffer.Length, (sbyte*)(tensor + sizeof(Int64)), size, status); - _handle = handle; - status.Check(true); - } - - public unsafe Tensor(NDArray nd, TF_DataType? tensorDType = null) - { - if (tensorDType == TF_DataType.TF_STRING && nd.dtype.Name == "Byte") - { - var buffer = nd.Data(); - var size = c_api.TF_StringEncodedSize((UIntPtr)buffer.Length); - var handle = TF_AllocateTensor(TF_DataType.TF_STRING, IntPtr.Zero, 0, (UIntPtr)((ulong)size + 8)); - - IntPtr tensor = c_api.TF_TensorData(handle); - Marshal.WriteInt64(tensor, 0); - fixed (byte* src = &buffer[0]) - c_api.TF_StringEncode(src, (UIntPtr)buffer.Length, (sbyte*)(tensor + sizeof(Int64)), size, status); - - status.Check(true); - _handle=handle; - IsMemoryOwner = false; - return; - } - _handle = Allocate(nd, tensorDType: tensorDType); - IsMemoryOwner = true; - } - - private unsafe IntPtr Allocate(NDArray nd, TF_DataType? tensorDType = null) - { - IntPtr dotHandle = IntPtr.Zero; - int buffersize = 0; - - if (nd.dtype.Name != "String") - { - buffersize = (nd.size * nd.dtypesize); - dotHandle = Marshal.AllocHGlobal(buffersize); - } - - var dataType = ToTFDataType(nd.dtype); - // shape - var dims = nd.shape.Select(x => (long)x).ToArray(); - var nd1 = nd.ravel(); - switch (nd.dtype.Name) - { - case "Boolean": - var boolVals = Array.ConvertAll(nd1.Data(), x => Convert.ToByte(x)); - Marshal.Copy(boolVals, 0, dotHandle, nd.size); - break; - case "Int16": - Marshal.Copy(nd1.Data(), 0, dotHandle, nd.size); - break; - case "Int32": - Marshal.Copy(nd1.Data(), 0, dotHandle, nd.size); - break; - case "Int64": - Marshal.Copy(nd1.Data(), 0, dotHandle, nd.size); - break; - case "Single": - Marshal.Copy(nd1.Data(), 0, dotHandle, nd.size); - break; - case "Double": - Marshal.Copy(nd1.Data(), 0, dotHandle, nd.size); - break; - case "Byte": - Marshal.Copy(nd1.Data(), 0, dotHandle, nd.size); - break; - case "String": - return new Tensor(UTF8Encoding.UTF8.GetBytes(nd.Data(0)), TF_DataType.TF_STRING); - default: - throw new NotImplementedException($"Marshal.Copy failed for {nd.dtype.Name}."); - } - var tfHandle = c_api.TF_NewTensor(dataType, - dims, - dims.Length, - dotHandle, - (UIntPtr)buffersize, - _hGlobalDeallocator, - ref _deallocatorArgs); - - return tfHandle; - } - - public Tensor(Operation op, int value_index, TF_DataType dtype) - { - _op = op; - _value_index = value_index; - _dtype = dtype; - _id = ops.uid(); - } - - - /// - /// Creates a new tensor from the given array without copying memory. The array is pinned down and the pointer passed on. - /// - /// Represents the tensor shape. - /// The linear array of data, the data must fit in the tensor with the specified dimensions. - /// The number of bytes in memory of a single array element - /// - /// Use the FromBuffer method to create a tensor that has the specified dimensions - /// and is initialized with data from the data array. The data is copied starting - /// at the start offset, for count bytes and is laid out into the tensor following the - /// specified dimensions. - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - protected unsafe IntPtr CreateTensorWithoutCopying(TF_DataType dt, long[] shape, Array data, int element_size) - { - if (dt == TF_DataType.TF_STRING && data is byte[]) - { - var buffer = (byte[])data; - var size = c_api.TF_StringEncodedSize((UIntPtr)buffer.Length); - var handle = TF_AllocateTensor(TF_DataType.TF_STRING, IntPtr.Zero, 0, (UIntPtr)((ulong)size + 8)); - - IntPtr tensor = c_api.TF_TensorData(handle); - Marshal.WriteInt64(tensor, 0); - fixed (byte* src = &buffer[0]) - c_api.TF_StringEncode(src, (UIntPtr)buffer.Length, (sbyte*)(tensor + sizeof(Int64)), size, status); - - status.Check(true); - return handle; - } - return CreateTensorWithoutCopying(dt, shape, data, 0, data.Length, element_size); - } - - /// - /// Creates a new tensor from a subsection of the given array without copying memory. The array is pinned down and the pointer passed on. - /// - /// Represents the tensor shape. - /// The linear array of data, the data must fit in the tensor with the specified dimensions. - /// The offset into the provided data array where the data resides. - /// The number of elements to copy from data. - /// The number of bytes in memory of a single array element - /// - /// Use the FromBuffer method to create a tensor that has the specified dimensions - /// and is initialized with data from the data array. The data is copied starting - /// at the start offset, for count bytes and is laid out into the tensor following the - /// specified dimensions. - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - protected unsafe IntPtr CreateTensorWithoutCopying(TF_DataType dt, long[] shape, Array data, int start, int count, int element_size) - { - if (start < 0 || start > data.Length - count) - throw new ArgumentException($"Array length {data.Length} does not match the given shape {new Shape(shape.Cast().ToArray())}"); - - // get a handle to the pinned array which we will pass on to the tensor computation engine to use - var gcHandle = GCHandle.Alloc(data, GCHandleType.Pinned); - _deallocatorArgs = new DeallocatorArgs() { gc_handle = GCHandle.ToIntPtr(gcHandle) }; - if (shape == null || shape.Length == 0) - return TF_NewTensor(dt, new long[0], 0, gcHandle.AddrOfPinnedObject() + start * element_size, (UIntPtr)(count * element_size), _gcHandleDeallocator, ref _deallocatorArgs); - else - return TF_NewTensor(dt, shape, shape.Length, gcHandle.AddrOfPinnedObject() + start * element_size, (UIntPtr)(count * element_size), _gcHandleDeallocator, ref _deallocatorArgs); - } - - [MonoPInvokeCallback(typeof(Deallocator))] - internal static void FreeHGlobalMemory(IntPtr dataPtr, IntPtr len, ref DeallocatorArgs args) - { - if (args.deallocator_called) - return; - Marshal.FreeHGlobal(dataPtr); - args.deallocator_called = true; - } - - [MonoPInvokeCallback(typeof(Deallocator))] - internal static void FreeGCHandle(IntPtr dataPtr, IntPtr len, ref DeallocatorArgs args) - { - if (args.deallocator_called || args.gc_handle == IntPtr.Zero) - return; - // note: since the ptr given to tensorflow is just the addr of the pinned object we can not directly free it! we need to free the gcHandle instead - GCHandle.FromIntPtr(args.gc_handle).Free(); - args.deallocator_called = true; - } - - [MonoPInvokeCallback(typeof(Deallocator))] - internal static void FreeNothing(IntPtr dataPtr, IntPtr len, ref DeallocatorArgs args) - { - args.deallocator_called = true; - } - - } - - /// - /// This attribute can be applied to callback functions that will be invoked - /// from unmanaged code to managed code. - /// - /// - /// - /// [TensorFlow.MonoPInvokeCallback (typeof (BufferReleaseFunc))] - /// internal static void MyFreeFunc (IntPtr data, IntPtr length){..} - /// - /// - public sealed class MonoPInvokeCallbackAttribute : Attribute - { - /// - /// Use this constructor to annotate the type of the callback function that - /// will be invoked from unmanaged code. - /// - /// T. - public MonoPInvokeCallbackAttribute(Type t) { } - } - -} +/***************************************************************************** + Copyright 2018 The TensorFlow.NET Authors. All Rights Reserved. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +******************************************************************************/ + +using NumSharp; +using System; +using System.Linq; +using System.Numerics; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Text; +using static Tensorflow.c_api; + +namespace Tensorflow +{ + public partial class Tensor + { + /// + /// true if unmanaged buffer has been freed. + /// + private bool _deallocator_called => _deallocatorArgs.deallocator_called; + + /// + /// true if the Tensor was created from a managed array + /// + private bool _isPinnedArray => _deallocatorArgs.gc_handle != IntPtr.Zero; + + /// + /// True only if the Tensor object was created in a way that the Tensor object itself allocated memory or pinned a managed object. + /// False if the Tensor was created from a pointer + /// + public bool IsMemoryOwner { get; private set; } + + /// + /// This holds values that are used by the unmanaged deallocator callback + /// + private DeallocatorArgs _deallocatorArgs = new DeallocatorArgs() { gc_handle = IntPtr.Zero }; + + // note: they must be assigned to a static variable in order to work as unmanaged callbacks + static Deallocator _hGlobalDeallocator = FreeHGlobalMemory; + static Deallocator _gcHandleDeallocator = FreeGCHandle; + private static Deallocator _nothingDeallocator = FreeNothing; + + /// + /// Create a Tensor object from an existing TF handle + /// + /// + public Tensor(IntPtr handle) + { + _handle = handle; + IsMemoryOwner = false; + } + + /// + /// Create a new Tensor from the given unmanaged memory pointer (which must be allocated, fixed or pinned by the caller) + /// Note: the caller is responsible for freeing the memory. Calling Dispose on this object will dispose the TensorFlow tensor + /// but not the memory itself! + /// + /// Pointer to unmanaged, fixed or pinned memory which the caller owns + /// Tensor shape + /// TF data type + /// Size of the tensor in memory + public Tensor(IntPtr ptr, long[] shape, TF_DataType dType, int num_bytes) + { + _handle = TF_NewTensor(dType, dims: shape, num_dims: shape.Length, data: ptr, len: (UIntPtr)num_bytes, deallocator: _nothingDeallocator, ref _deallocatorArgs); + IsMemoryOwner = false; + } + +#if _REGEN + %types=["sbyte", "byte", "short", "ushort", "int", "uint", "long", "ulong", "float", "double", "Complex"] + %foreach types% + + /// + /// Create a 1d Tensor from the given linear array and shape + /// + public Tensor(#1[] data, TF_DataType? dType = null) + { + _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(#1)), new long[]{data.Length}, data, Marshal.SizeOf<#1>()); + IsMemoryOwner=true; + } + + /// + /// Create a N-dimensional Tensor from the given array + /// + public Tensor(#1[] data, long[] shape, TF_DataType? dType = null) + { + _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(#1)), shape, data, Marshal.SizeOf<#1>()); + IsMemoryOwner=true; + } + + /// + /// Create a scalar Tensor from the given value + /// + public unsafe Tensor(#1 value, TF_DataType? dType = null) + { + var v = (#1*)Marshal.AllocHGlobal(sizeof(#1)); + *v = value; + _handle = TF_NewTensor(dType ?? dtypes.as_dtype(typeof(#1)), dims:new long[0], num_dims: 0, data: (IntPtr)v, len: (UIntPtr)sizeof(#1), deallocator: _hGlobalDeallocator, ref _deallocatorArgs); + IsMemoryOwner=true; + } + % +#else + + + /// + /// Create a 1d Tensor from the given linear array and shape + /// + public Tensor(sbyte[] data, TF_DataType? dType = null) + { + _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(sbyte)), new long[]{data.Length}, data, Marshal.SizeOf()); + IsMemoryOwner=true; + } + + /// + /// Create a N-dimensional Tensor from the given array + /// + public Tensor(sbyte[] data, long[] shape, TF_DataType? dType = null) + { + _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(sbyte)), shape, data, Marshal.SizeOf()); + IsMemoryOwner=true; + } + + /// + /// Create a scalar Tensor from the given value + /// + public unsafe Tensor(sbyte value, TF_DataType? dType = null) + { + var v = (sbyte*)Marshal.AllocHGlobal(sizeof(sbyte)); + *v = value; + _handle = TF_NewTensor(dType ?? dtypes.as_dtype(typeof(sbyte)), dims:new long[0], num_dims: 0, data: (IntPtr)v, len: (UIntPtr)sizeof(sbyte), deallocator: _hGlobalDeallocator, ref _deallocatorArgs); + IsMemoryOwner=true; + } + + /// + /// Create a 1d Tensor from the given linear array and shape + /// + public Tensor(byte[] data, TF_DataType? dType = null) + { + _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(byte)), new long[]{data.Length}, data, Marshal.SizeOf()); + IsMemoryOwner=true; + } + + /// + /// Create a N-dimensional Tensor from the given array + /// + public Tensor(byte[] data, long[] shape, TF_DataType? dType = null) + { + _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(byte)), shape, data, Marshal.SizeOf()); + IsMemoryOwner=true; + } + + /// + /// Create a scalar Tensor from the given value + /// + public unsafe Tensor(byte value, TF_DataType? dType = null) + { + var v = (byte*)Marshal.AllocHGlobal(sizeof(byte)); + *v = value; + _handle = TF_NewTensor(dType ?? dtypes.as_dtype(typeof(byte)), dims:new long[0], num_dims: 0, data: (IntPtr)v, len: (UIntPtr)sizeof(byte), deallocator: _hGlobalDeallocator, ref _deallocatorArgs); + IsMemoryOwner=true; + } + + /// + /// Create a 1d Tensor from the given linear array and shape + /// + public Tensor(short[] data, TF_DataType? dType = null) + { + _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(short)), new long[]{data.Length}, data, Marshal.SizeOf()); + IsMemoryOwner=true; + } + + /// + /// Create a N-dimensional Tensor from the given array + /// + public Tensor(short[] data, long[] shape, TF_DataType? dType = null) + { + _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(short)), shape, data, Marshal.SizeOf()); + IsMemoryOwner=true; + } + + /// + /// Create a scalar Tensor from the given value + /// + public unsafe Tensor(short value, TF_DataType? dType = null) + { + var v = (short*)Marshal.AllocHGlobal(sizeof(short)); + *v = value; + _handle = TF_NewTensor(dType ?? dtypes.as_dtype(typeof(short)), dims:new long[0], num_dims: 0, data: (IntPtr)v, len: (UIntPtr)sizeof(short), deallocator: _hGlobalDeallocator, ref _deallocatorArgs); + IsMemoryOwner=true; + } + + /// + /// Create a 1d Tensor from the given linear array and shape + /// + public Tensor(ushort[] data, TF_DataType? dType = null) + { + _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(ushort)), new long[]{data.Length}, data, Marshal.SizeOf()); + IsMemoryOwner=true; + } + + /// + /// Create a N-dimensional Tensor from the given array + /// + public Tensor(ushort[] data, long[] shape, TF_DataType? dType = null) + { + _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(ushort)), shape, data, Marshal.SizeOf()); + IsMemoryOwner=true; + } + + /// + /// Create a scalar Tensor from the given value + /// + public unsafe Tensor(ushort value, TF_DataType? dType = null) + { + var v = (ushort*)Marshal.AllocHGlobal(sizeof(ushort)); + *v = value; + _handle = TF_NewTensor(dType ?? dtypes.as_dtype(typeof(ushort)), dims:new long[0], num_dims: 0, data: (IntPtr)v, len: (UIntPtr)sizeof(ushort), deallocator: _hGlobalDeallocator, ref _deallocatorArgs); + IsMemoryOwner=true; + } + + /// + /// Create a 1d Tensor from the given linear array and shape + /// + public Tensor(int[] data, TF_DataType? dType = null) + { + _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(int)), new long[]{data.Length}, data, Marshal.SizeOf()); + IsMemoryOwner=true; + } + + /// + /// Create a N-dimensional Tensor from the given array + /// + public Tensor(int[] data, long[] shape, TF_DataType? dType = null) + { + _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(int)), shape, data, Marshal.SizeOf()); + IsMemoryOwner=true; + } + + /// + /// Create a scalar Tensor from the given value + /// + public unsafe Tensor(int value, TF_DataType? dType = null) + { + var v = (int*)Marshal.AllocHGlobal(sizeof(int)); + *v = value; + _handle = TF_NewTensor(dType ?? dtypes.as_dtype(typeof(int)), dims:new long[0], num_dims: 0, data: (IntPtr)v, len: (UIntPtr)sizeof(int), deallocator: _hGlobalDeallocator, ref _deallocatorArgs); + IsMemoryOwner=true; + } + + /// + /// Create a 1d Tensor from the given linear array and shape + /// + public Tensor(uint[] data, TF_DataType? dType = null) + { + _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(uint)), new long[]{data.Length}, data, Marshal.SizeOf()); + IsMemoryOwner=true; + } + + /// + /// Create a N-dimensional Tensor from the given array + /// + public Tensor(uint[] data, long[] shape, TF_DataType? dType = null) + { + _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(uint)), shape, data, Marshal.SizeOf()); + IsMemoryOwner=true; + } + + /// + /// Create a scalar Tensor from the given value + /// + public unsafe Tensor(uint value, TF_DataType? dType = null) + { + var v = (uint*)Marshal.AllocHGlobal(sizeof(uint)); + *v = value; + _handle = TF_NewTensor(dType ?? dtypes.as_dtype(typeof(uint)), dims:new long[0], num_dims: 0, data: (IntPtr)v, len: (UIntPtr)sizeof(uint), deallocator: _hGlobalDeallocator, ref _deallocatorArgs); + IsMemoryOwner=true; + } + + /// + /// Create a 1d Tensor from the given linear array and shape + /// + public Tensor(long[] data, TF_DataType? dType = null) + { + _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(long)), new long[]{data.Length}, data, Marshal.SizeOf()); + IsMemoryOwner=true; + } + + /// + /// Create a N-dimensional Tensor from the given array + /// + public Tensor(long[] data, long[] shape, TF_DataType? dType = null) + { + _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(long)), shape, data, Marshal.SizeOf()); + IsMemoryOwner=true; + } + + /// + /// Create a scalar Tensor from the given value + /// + public unsafe Tensor(long value, TF_DataType? dType = null) + { + var v = (long*)Marshal.AllocHGlobal(sizeof(long)); + *v = value; + _handle = TF_NewTensor(dType ?? dtypes.as_dtype(typeof(long)), dims:new long[0], num_dims: 0, data: (IntPtr)v, len: (UIntPtr)sizeof(long), deallocator: _hGlobalDeallocator, ref _deallocatorArgs); + IsMemoryOwner=true; + } + + /// + /// Create a 1d Tensor from the given linear array and shape + /// + public Tensor(ulong[] data, TF_DataType? dType = null) + { + _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(ulong)), new long[]{data.Length}, data, Marshal.SizeOf()); + IsMemoryOwner=true; + } + + /// + /// Create a N-dimensional Tensor from the given array + /// + public Tensor(ulong[] data, long[] shape, TF_DataType? dType = null) + { + _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(ulong)), shape, data, Marshal.SizeOf()); + IsMemoryOwner=true; + } + + /// + /// Create a scalar Tensor from the given value + /// + public unsafe Tensor(ulong value, TF_DataType? dType = null) + { + var v = (ulong*)Marshal.AllocHGlobal(sizeof(ulong)); + *v = value; + _handle = TF_NewTensor(dType ?? dtypes.as_dtype(typeof(ulong)), dims:new long[0], num_dims: 0, data: (IntPtr)v, len: (UIntPtr)sizeof(ulong), deallocator: _hGlobalDeallocator, ref _deallocatorArgs); + IsMemoryOwner=true; + } + + /// + /// Create a 1d Tensor from the given linear array and shape + /// + public Tensor(float[] data, TF_DataType? dType = null) + { + _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(float)), new long[]{data.Length}, data, Marshal.SizeOf()); + IsMemoryOwner=true; + } + + /// + /// Create a N-dimensional Tensor from the given array + /// + public Tensor(float[] data, long[] shape, TF_DataType? dType = null) + { + _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(float)), shape, data, Marshal.SizeOf()); + IsMemoryOwner=true; + } + + /// + /// Create a scalar Tensor from the given value + /// + public unsafe Tensor(float value, TF_DataType? dType = null) + { + var v = (float*)Marshal.AllocHGlobal(sizeof(float)); + *v = value; + _handle = TF_NewTensor(dType ?? dtypes.as_dtype(typeof(float)), dims:new long[0], num_dims: 0, data: (IntPtr)v, len: (UIntPtr)sizeof(float), deallocator: _hGlobalDeallocator, ref _deallocatorArgs); + IsMemoryOwner=true; + } + + /// + /// Create a 1d Tensor from the given linear array and shape + /// + public Tensor(double[] data, TF_DataType? dType = null) + { + _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(double)), new long[]{data.Length}, data, Marshal.SizeOf()); + IsMemoryOwner=true; + } + + /// + /// Create a N-dimensional Tensor from the given array + /// + public Tensor(double[] data, long[] shape, TF_DataType? dType = null) + { + _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(double)), shape, data, Marshal.SizeOf()); + IsMemoryOwner=true; + } + + /// + /// Create a scalar Tensor from the given value + /// + public unsafe Tensor(double value, TF_DataType? dType = null) + { + var v = (double*)Marshal.AllocHGlobal(sizeof(double)); + *v = value; + _handle = TF_NewTensor(dType ?? dtypes.as_dtype(typeof(double)), dims:new long[0], num_dims: 0, data: (IntPtr)v, len: (UIntPtr)sizeof(double), deallocator: _hGlobalDeallocator, ref _deallocatorArgs); + IsMemoryOwner=true; + } + + /// + /// Create a 1d Tensor from the given linear array and shape + /// + public Tensor(Complex[] data, TF_DataType? dType = null) + { + _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(Complex)), new long[]{data.Length}, data, Marshal.SizeOf()); + IsMemoryOwner=true; + } + + /// + /// Create a N-dimensional Tensor from the given array + /// + public Tensor(Complex[] data, long[] shape, TF_DataType? dType = null) + { + _handle = CreateTensorWithoutCopying(dType ?? dtypes.as_dtype(typeof(Complex)), shape, data, Marshal.SizeOf()); + IsMemoryOwner=true; + } + + /// + /// Create a scalar Tensor from the given value + /// + public unsafe Tensor(Complex value, TF_DataType? dType = null) + { + var v = (Complex*)Marshal.AllocHGlobal(sizeof(Complex)); + *v = value; + _handle = TF_NewTensor(dType ?? dtypes.as_dtype(typeof(Complex)), dims:new long[0], num_dims: 0, data: (IntPtr)v, len: (UIntPtr)sizeof(Complex), deallocator: _hGlobalDeallocator, ref _deallocatorArgs); + IsMemoryOwner=true; + } +#endif + + /// + /// Create a string Tensor from the given string + /// + public unsafe Tensor(string str) + { + var buffer = Encoding.UTF8.GetBytes(str); + var size = c_api.TF_StringEncodedSize((UIntPtr)buffer.Length); + var handle = TF_AllocateTensor(TF_DataType.TF_STRING, IntPtr.Zero, 0, (UIntPtr)((ulong)size + 8)); + + IntPtr tensor = c_api.TF_TensorData(handle); + Marshal.WriteInt64(tensor, 0); + fixed (byte* src = &buffer[0]) + c_api.TF_StringEncode(src, (UIntPtr)buffer.Length, (sbyte*)(tensor + sizeof(Int64)), size, status); + _handle = handle; + status.Check(true); + } + + public unsafe Tensor(NDArray nd, TF_DataType? tensorDType = null) + { + if (tensorDType == TF_DataType.TF_STRING && nd.dtype.Name == "Byte") + { + var buffer = nd.Data(); + var size = c_api.TF_StringEncodedSize((UIntPtr)buffer.Length); + var handle = TF_AllocateTensor(TF_DataType.TF_STRING, IntPtr.Zero, 0, (UIntPtr)((ulong)size + 8)); + + IntPtr tensor = c_api.TF_TensorData(handle); + Marshal.WriteInt64(tensor, 0); + fixed (byte* src = &buffer[0]) + c_api.TF_StringEncode(src, (UIntPtr)buffer.Length, (sbyte*)(tensor + sizeof(Int64)), size, status); + + status.Check(true); + _handle=handle; + IsMemoryOwner = false; + return; + } + _handle = Allocate(nd, tensorDType: tensorDType); + IsMemoryOwner = true; + } + + private unsafe IntPtr Allocate(NDArray nd, TF_DataType? tensorDType = null) + { + IntPtr dotHandle = IntPtr.Zero; + int buffersize = 0; + + if (nd.dtype.Name != "String") + { + buffersize = (nd.size * nd.dtypesize); + dotHandle = Marshal.AllocHGlobal(buffersize); + } + + var dataType = ToTFDataType(nd.dtype); + // shape + var dims = nd.shape.Select(x => (long)x).ToArray(); + var nd1 = nd.ravel(); + switch (nd.dtype.Name) + { + case "Boolean": + var boolVals = Array.ConvertAll(nd1.Data(), x => Convert.ToByte(x)); + Marshal.Copy(boolVals, 0, dotHandle, nd.size); + break; + case "Int16": + Marshal.Copy(nd1.Data(), 0, dotHandle, nd.size); + break; + case "Int32": + Marshal.Copy(nd1.Data(), 0, dotHandle, nd.size); + break; + case "Int64": + Marshal.Copy(nd1.Data(), 0, dotHandle, nd.size); + break; + case "Single": + Marshal.Copy(nd1.Data(), 0, dotHandle, nd.size); + break; + case "Double": + Marshal.Copy(nd1.Data(), 0, dotHandle, nd.size); + break; + case "Byte": + Marshal.Copy(nd1.Data(), 0, dotHandle, nd.size); + break; + case "String": + return new Tensor(UTF8Encoding.UTF8.GetBytes(nd.Data(0)), TF_DataType.TF_STRING); + default: + throw new NotImplementedException($"Marshal.Copy failed for {nd.dtype.Name}."); + } + var tfHandle = c_api.TF_NewTensor(dataType, + dims, + dims.Length, + dotHandle, + (UIntPtr)buffersize, + _hGlobalDeallocator, + ref _deallocatorArgs); + + return tfHandle; + } + + public Tensor(Operation op, int value_index, TF_DataType dtype) + { + _op = op; + _value_index = value_index; + _dtype = dtype; + _id = ops.uid(); + } + + + /// + /// Creates a new tensor from the given array without copying memory. The array is pinned down and the pointer passed on. + /// + /// Represents the tensor shape. + /// The linear array of data, the data must fit in the tensor with the specified dimensions. + /// The number of bytes in memory of a single array element + /// + /// Use the FromBuffer method to create a tensor that has the specified dimensions + /// and is initialized with data from the data array. The data is copied starting + /// at the start offset, for count bytes and is laid out into the tensor following the + /// specified dimensions. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + protected unsafe IntPtr CreateTensorWithoutCopying(TF_DataType dt, long[] shape, Array data, int element_size) + { + if (dt == TF_DataType.TF_STRING && data is byte[]) + { + var buffer = (byte[])data; + var size = c_api.TF_StringEncodedSize((UIntPtr)buffer.Length); + var handle = TF_AllocateTensor(TF_DataType.TF_STRING, IntPtr.Zero, 0, (UIntPtr)((ulong)size + 8)); + + IntPtr tensor = c_api.TF_TensorData(handle); + Marshal.WriteInt64(tensor, 0); + fixed (byte* src = &buffer[0]) + c_api.TF_StringEncode(src, (UIntPtr)buffer.Length, (sbyte*)(tensor + sizeof(Int64)), size, status); + + status.Check(true); + return handle; + } + return CreateTensorWithoutCopying(dt, shape, data, 0, data.Length, element_size); + } + + /// + /// Creates a new tensor from a subsection of the given array without copying memory. The array is pinned down and the pointer passed on. + /// + /// Represents the tensor shape. + /// The linear array of data, the data must fit in the tensor with the specified dimensions. + /// The offset into the provided data array where the data resides. + /// The number of elements to copy from data. + /// The number of bytes in memory of a single array element + /// + /// Use the FromBuffer method to create a tensor that has the specified dimensions + /// and is initialized with data from the data array. The data is copied starting + /// at the start offset, for count bytes and is laid out into the tensor following the + /// specified dimensions. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + protected unsafe IntPtr CreateTensorWithoutCopying(TF_DataType dt, long[] shape, Array data, int start, int count, int element_size) + { + if (start < 0 || start > data.Length - count) + throw new ArgumentException($"Array length {data.Length} does not match the given shape {new Shape(shape.Cast().ToArray())}"); + + // get a handle to the pinned array which we will pass on to the tensor computation engine to use + var gcHandle = GCHandle.Alloc(data, GCHandleType.Pinned); + _deallocatorArgs = new DeallocatorArgs() { gc_handle = GCHandle.ToIntPtr(gcHandle) }; + if (shape == null || shape.Length == 0) + return TF_NewTensor(dt, new long[0], 0, gcHandle.AddrOfPinnedObject() + start * element_size, (UIntPtr)(count * element_size), _gcHandleDeallocator, ref _deallocatorArgs); + else + return TF_NewTensor(dt, shape, shape.Length, gcHandle.AddrOfPinnedObject() + start * element_size, (UIntPtr)(count * element_size), _gcHandleDeallocator, ref _deallocatorArgs); + } + + [MonoPInvokeCallback(typeof(Deallocator))] + internal static void FreeHGlobalMemory(IntPtr dataPtr, IntPtr len, ref DeallocatorArgs args) + { + if (args.deallocator_called) + return; + Marshal.FreeHGlobal(dataPtr); + args.deallocator_called = true; + } + + [MonoPInvokeCallback(typeof(Deallocator))] + internal static void FreeGCHandle(IntPtr dataPtr, IntPtr len, ref DeallocatorArgs args) + { + if (args.deallocator_called || args.gc_handle == IntPtr.Zero) + return; + // note: since the ptr given to tensorflow is just the addr of the pinned object we can not directly free it! we need to free the gcHandle instead + GCHandle.FromIntPtr(args.gc_handle).Free(); + args.deallocator_called = true; + } + + [MonoPInvokeCallback(typeof(Deallocator))] + internal static void FreeNothing(IntPtr dataPtr, IntPtr len, ref DeallocatorArgs args) + { + args.deallocator_called = true; + } + + } + + /// + /// This attribute can be applied to callback functions that will be invoked + /// from unmanaged code to managed code. + /// + /// + /// + /// [TensorFlow.MonoPInvokeCallback (typeof (BufferReleaseFunc))] + /// internal static void MyFreeFunc (IntPtr data, IntPtr length){..} + /// + /// + public sealed class MonoPInvokeCallbackAttribute : Attribute + { + /// + /// Use this constructor to annotate the type of the callback function that + /// will be invoked from unmanaged code. + /// + /// T. + public MonoPInvokeCallbackAttribute(Type t) { } + } + +} diff --git a/src/TensorFlowNET.Core/Tensors/Tensor.Explicit.cs b/src/TensorFlowNET.Core/Tensors/Tensor.Explicit.cs new file mode 100644 index 00000000..640fce7d --- /dev/null +++ b/src/TensorFlowNET.Core/Tensors/Tensor.Explicit.cs @@ -0,0 +1,92 @@ +using System; + +namespace Tensorflow +{ + public partial class Tensor + { + public static explicit operator bool(Tensor tensor) + { + EnsureScalar(tensor); + return tensor.Data()[0]; + } + + public static explicit operator sbyte(Tensor tensor) + { + EnsureScalar(tensor); + return tensor.Data()[0]; + } + + public static explicit operator byte(Tensor tensor) + { + EnsureScalar(tensor); + return tensor.Data()[0]; + } + + public static explicit operator ushort(Tensor tensor) + { + EnsureScalar(tensor); + return tensor.Data()[0]; + } + + public static explicit operator short(Tensor tensor) + { + EnsureScalar(tensor); + return tensor.Data()[0]; + } + + public static explicit operator int(Tensor tensor) + { + EnsureScalar(tensor); + return tensor.Data()[0]; + } + + public static explicit operator uint(Tensor tensor) + { + EnsureScalar(tensor); + return tensor.Data()[0]; + } + + public static explicit operator long(Tensor tensor) + { + EnsureScalar(tensor); + return tensor.Data()[0]; + } + + public static explicit operator ulong(Tensor tensor) + { + EnsureScalar(tensor); + return tensor.Data()[0]; + } + + public static explicit operator float(Tensor tensor) + { + EnsureScalar(tensor); + return tensor.Data()[0]; + } + + public static explicit operator double(Tensor tensor) + { + EnsureScalar(tensor); + return tensor.Data()[0]; + } + + private static void EnsureScalar(Tensor tensor) + { + if (tensor == null) + { + throw new ArgumentNullException(nameof(tensor)); + } + + if (tensor.TensorShape.NDim != 0) + { + throw new ArgumentException("Tensor must have 0 dimensions in order to convert to scalar"); + } + + if (tensor.TensorShape.Size != 1) + { + throw new ArgumentException("Tensor must have size 1 in order to convert to scalar"); + } + } + + } +} diff --git a/src/TensorFlowNET.Core/Tensors/Tensor.Implicit.cs b/src/TensorFlowNET.Core/Tensors/Tensor.Implicit.cs index 2f4b5d26..273222c5 100644 --- a/src/TensorFlowNET.Core/Tensors/Tensor.Implicit.cs +++ b/src/TensorFlowNET.Core/Tensors/Tensor.Implicit.cs @@ -15,30 +15,64 @@ ******************************************************************************/ using System; -using System.Collections.Generic; -using System.Text; namespace Tensorflow { public partial class Tensor { - /// - /// Issue unresolved, will cause name_scope problem. - /// - /// - /*public static implicit operator Tensor(double scalar) + public static implicit operator Tensor(bool value) { - return constant_op.constant(scalar); - }*/ + return tf.constant(value, TF_DataType.TF_BOOL); + } + + public static implicit operator Tensor(sbyte value) + { + return tf.constant(value, TF_DataType.TF_INT8); + } + + public static implicit operator Tensor(byte value) + { + return tf.constant(value, TF_DataType.TF_INT16); + } + + public static implicit operator Tensor(ushort value) + { + return tf.constant(value, TF_DataType.TF_UINT16); + } + + public static implicit operator Tensor(short value) + { + return tf.constant(value, TF_DataType.TF_INT16); + } - /*public static implicit operator Tensor(int scalar) + public static implicit operator Tensor(int value) { - return constant_op.constant(scalar); - }*/ + return tf.constant(value, TF_DataType.TF_INT32); + } + + public static implicit operator Tensor(uint value) + { + return tf.constant(value, TF_DataType.TF_UINT32); + } + + public static implicit operator Tensor(long value) + { + return tf.constant(value, TF_DataType.TF_INT64); + } + + public static implicit operator Tensor(ulong value) + { + return tf.constant(value, TF_DataType.TF_UINT64); + } + + public static implicit operator Tensor(float value) + { + return tf.constant(value, TF_DataType.TF_FLOAT); + } - public static implicit operator int(Tensor tensor) + public static implicit operator Tensor(double value) { - return tensor.Data()[0]; + return tf.constant(value, TF_DataType.TF_DOUBLE); } public static implicit operator IntPtr(Tensor tensor) diff --git a/src/TensorFlowNET.Core/Tensors/Tensor.Operators.cs b/src/TensorFlowNET.Core/Tensors/Tensor.Operators.cs index a1606da3..0b9c7f3e 100644 --- a/src/TensorFlowNET.Core/Tensors/Tensor.Operators.cs +++ b/src/TensorFlowNET.Core/Tensors/Tensor.Operators.cs @@ -15,8 +15,6 @@ ******************************************************************************/ using System; -using System.Collections.Generic; -using System.Text; using static Tensorflow.Python; namespace Tensorflow @@ -45,6 +43,25 @@ namespace Tensorflow public static Tensor operator *(double x, Tensor y) => BinaryOpWrapper("mul", x, y); public static Tensor operator *(Tensor x, Tensor y) => BinaryOpWrapper("mul", x, y); public static Tensor operator *(Tensor x, int y) => BinaryOpWrapper("mul", x, y); + public static Tensor operator *(Tensor tensor, bool constant) => BinaryOpWrapper("mul", tensor, constant); + public static Tensor operator *(Tensor tensor, sbyte constant) => BinaryOpWrapper("mul", tensor, constant); + public static Tensor operator *(Tensor tensor, byte constant) => BinaryOpWrapper("mul", tensor, constant); + public static Tensor operator *(Tensor tensor, ushort constant) => BinaryOpWrapper("mul", tensor, constant); + public static Tensor operator *(Tensor tensor, short constant) => BinaryOpWrapper("mul", tensor, constant); + public static Tensor operator *(Tensor tensor, uint constant) => BinaryOpWrapper("mul", tensor, constant); + public static Tensor operator *(Tensor tensor, long constant) => BinaryOpWrapper("mul", tensor, constant); + public static Tensor operator *(Tensor tensor, ulong constant) => BinaryOpWrapper("mul", tensor, constant); + public static Tensor operator *(Tensor tensor, float constant) => BinaryOpWrapper("mul", tensor, constant); + public static Tensor operator *(Tensor tensor, double constant) => BinaryOpWrapper("mul", tensor, constant); + public static Tensor operator *(bool constant, Tensor tensor) => BinaryOpWrapper("mul", constant, tensor); + public static Tensor operator *(sbyte constant, Tensor tensor) => BinaryOpWrapper("mul", constant, tensor); + public static Tensor operator *(byte constant, Tensor tensor) => BinaryOpWrapper("mul", constant, tensor); + public static Tensor operator *(ushort constant, Tensor tensor) => BinaryOpWrapper("mul", constant, tensor); + public static Tensor operator *(short constant, Tensor tensor) => BinaryOpWrapper("mul", constant, tensor); + public static Tensor operator *(int constant, Tensor tensor) => BinaryOpWrapper("mul", constant, tensor); + public static Tensor operator *(uint constant, Tensor tensor) => BinaryOpWrapper("mul", constant, tensor); + public static Tensor operator *(long constant, Tensor tensor) => BinaryOpWrapper("mul", constant, tensor); + public static Tensor operator *(ulong constant, Tensor tensor) => BinaryOpWrapper("mul", constant, tensor); public static Tensor operator /(Tensor x, Tensor y) => BinaryOpWrapper("truediv", x, y); public static Tensor operator /(Tensor x, float y) => BinaryOpWrapper("truediv", x, y); @@ -67,9 +84,9 @@ namespace Tensorflow TF_DataType dtype = TF_DataType.DtInvalid; if (x is Tensor tl) dtype = tl.dtype.as_base_dtype(); - if( y is Tensor tr) + if (y is Tensor tr) dtype = tr.dtype.as_base_dtype(); - + var namescope = ops.name_scope(null, name, new { x, y }); return with(namescope, scope => { @@ -100,7 +117,7 @@ namespace Tensorflow return result; }); - + } } } diff --git a/src/TensorFlowNET.Core/Tensors/Tensor.cs b/src/TensorFlowNET.Core/Tensors/Tensor.cs index 4322131e..a2a77a7e 100644 --- a/src/TensorFlowNET.Core/Tensors/Tensor.cs +++ b/src/TensorFlowNET.Core/Tensors/Tensor.cs @@ -19,8 +19,6 @@ using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; -using System.Text; -using static Tensorflow.c_api; using static Tensorflow.Python; namespace Tensorflow diff --git a/src/TensorFlowNET.Core/Tensors/TensorBuffer.cs b/src/TensorFlowNET.Core/Tensors/TensorBuffer.cs index 6027e835..52c128d9 100644 --- a/src/TensorFlowNET.Core/Tensors/TensorBuffer.cs +++ b/src/TensorFlowNET.Core/Tensors/TensorBuffer.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Tensorflow +namespace Tensorflow { public class TensorBuffer { diff --git a/src/TensorFlowNET.Core/Tensors/TensorShape.cs b/src/TensorFlowNET.Core/Tensors/TensorShape.cs index e543fc9b..8559cbd4 100644 --- a/src/TensorFlowNET.Core/Tensors/TensorShape.cs +++ b/src/TensorFlowNET.Core/Tensors/TensorShape.cs @@ -1,9 +1,6 @@ -using Google.Protobuf.Collections; -using NumSharp; +using NumSharp; using System; -using System.Collections.Generic; using System.Linq; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Tensors/c_api.tensor.cs b/src/TensorFlowNET.Core/Tensors/c_api.tensor.cs index b9735dfb..cf208ed2 100644 --- a/src/TensorFlowNET.Core/Tensors/c_api.tensor.cs +++ b/src/TensorFlowNET.Core/Tensors/c_api.tensor.cs @@ -15,9 +15,7 @@ ******************************************************************************/ using System; -using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Tensors/constant_op.cs b/src/TensorFlowNET.Core/Tensors/constant_op.cs index 348a4551..8167d5ef 100644 --- a/src/TensorFlowNET.Core/Tensors/constant_op.cs +++ b/src/TensorFlowNET.Core/Tensors/constant_op.cs @@ -14,10 +14,8 @@ limitations under the License. ******************************************************************************/ -using NumSharp; using System; using System.Collections.Generic; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Tensors/dtypes.cs b/src/TensorFlowNET.Core/Tensors/dtypes.cs index 5000401a..c809c96b 100644 --- a/src/TensorFlowNET.Core/Tensors/dtypes.cs +++ b/src/TensorFlowNET.Core/Tensors/dtypes.cs @@ -15,8 +15,6 @@ ******************************************************************************/ using System; -using System.Collections.Generic; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Tensors/tensor_util.cs b/src/TensorFlowNET.Core/Tensors/tensor_util.cs index 85fc2518..473bb7ca 100644 --- a/src/TensorFlowNET.Core/Tensors/tensor_util.cs +++ b/src/TensorFlowNET.Core/Tensors/tensor_util.cs @@ -16,9 +16,7 @@ using NumSharp; using System; -using System.Collections.Generic; using System.Linq; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Tensors/tf.constant.cs b/src/TensorFlowNET.Core/Tensors/tf.constant.cs index 3f67589b..4ef951a3 100644 --- a/src/TensorFlowNET.Core/Tensors/tf.constant.cs +++ b/src/TensorFlowNET.Core/Tensors/tf.constant.cs @@ -15,9 +15,6 @@ ******************************************************************************/ using NumSharp; -using System; -using System.Collections.Generic; -using System.Text; namespace Tensorflow { @@ -45,7 +42,11 @@ namespace Tensorflow verify_shape: false, allow_broadcast: false); - public static Tensor zeros(Shape shape, TF_DataType dtype = TF_DataType.TF_FLOAT, string name = null) => array_ops.zeros(shape, dtype, name); + public static Tensor zeros(Shape shape, TF_DataType dtype = TF_DataType.TF_FLOAT, string name = null) + => array_ops.zeros(shape, dtype, name); + + public static Tensor ones(Shape shape, TF_DataType dtype = TF_DataType.TF_FLOAT, string name = null) + => array_ops.ones(shape, dtype, name); public static Tensor size(Tensor input, string name = null, diff --git a/src/TensorFlowNET.Core/Train/AdamOptimizer.cs b/src/TensorFlowNET.Core/Train/AdamOptimizer.cs index ce4277b3..c273f4d4 100644 --- a/src/TensorFlowNET.Core/Train/AdamOptimizer.cs +++ b/src/TensorFlowNET.Core/Train/AdamOptimizer.cs @@ -17,7 +17,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; using Tensorflow.Framework; using static Tensorflow.Python; diff --git a/src/TensorFlowNET.Core/Train/AutoTrackable.cs b/src/TensorFlowNET.Core/Train/AutoTrackable.cs index d3479f1b..d2198e37 100644 --- a/src/TensorFlowNET.Core/Train/AutoTrackable.cs +++ b/src/TensorFlowNET.Core/Train/AutoTrackable.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Tensorflow.Train +namespace Tensorflow.Train { public abstract class AutoTrackable : Trackable { diff --git a/src/TensorFlowNET.Core/Train/Checkpointable/CheckpointableBase.cs b/src/TensorFlowNET.Core/Train/Checkpointable/CheckpointableBase.cs index 466091fa..c1738f7f 100644 --- a/src/TensorFlowNET.Core/Train/Checkpointable/CheckpointableBase.cs +++ b/src/TensorFlowNET.Core/Train/Checkpointable/CheckpointableBase.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Tensorflow.Train; +using Tensorflow.Train; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Train/Distribute.cs b/src/TensorFlowNET.Core/Train/Distribute.cs index 0e632998..3edc4761 100644 --- a/src/TensorFlowNET.Core/Train/Distribute.cs +++ b/src/TensorFlowNET.Core/Train/Distribute.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Tensorflow +namespace Tensorflow { public static class Distribute { diff --git a/src/TensorFlowNET.Core/Train/GateGradientType.cs b/src/TensorFlowNET.Core/Train/GateGradientType.cs index 12c8a559..cdb1d396 100644 --- a/src/TensorFlowNET.Core/Train/GateGradientType.cs +++ b/src/TensorFlowNET.Core/Train/GateGradientType.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Tensorflow +namespace Tensorflow { public enum GateGradientType { diff --git a/src/TensorFlowNET.Core/Train/GradientDescentOptimizer.cs b/src/TensorFlowNET.Core/Train/GradientDescentOptimizer.cs index f8e06926..2d472f5a 100644 --- a/src/TensorFlowNET.Core/Train/GradientDescentOptimizer.cs +++ b/src/TensorFlowNET.Core/Train/GradientDescentOptimizer.cs @@ -14,10 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow.Train { /// diff --git a/src/TensorFlowNET.Core/Train/Optimizer.cs b/src/TensorFlowNET.Core/Train/Optimizer.cs index ef042e8f..3e1d86c5 100644 --- a/src/TensorFlowNET.Core/Train/Optimizer.cs +++ b/src/TensorFlowNET.Core/Train/Optimizer.cs @@ -17,7 +17,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; using Tensorflow.Framework; using Tensorflow.Train; using static Tensorflow.Python; diff --git a/src/TensorFlowNET.Core/Train/Saving/BaseSaverBuilder.cs b/src/TensorFlowNET.Core/Train/Saving/BaseSaverBuilder.cs index 589f9b6c..9deca740 100644 --- a/src/TensorFlowNET.Core/Train/Saving/BaseSaverBuilder.cs +++ b/src/TensorFlowNET.Core/Train/Saving/BaseSaverBuilder.cs @@ -17,7 +17,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; using Tensorflow.Operations; using static Tensorflow.Python; diff --git a/src/TensorFlowNET.Core/Train/Saving/BulkSaverBuilder.cs b/src/TensorFlowNET.Core/Train/Saving/BulkSaverBuilder.cs index 1919ab25..27f89f38 100644 --- a/src/TensorFlowNET.Core/Train/Saving/BulkSaverBuilder.cs +++ b/src/TensorFlowNET.Core/Train/Saving/BulkSaverBuilder.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Tensorflow +namespace Tensorflow { public class BulkSaverBuilder : BaseSaverBuilder, ISaverBuilder { diff --git a/src/TensorFlowNET.Core/Train/Saving/ISaverBuilder.cs b/src/TensorFlowNET.Core/Train/Saving/ISaverBuilder.cs index 2340e2f5..bc824221 100644 --- a/src/TensorFlowNET.Core/Train/Saving/ISaverBuilder.cs +++ b/src/TensorFlowNET.Core/Train/Saving/ISaverBuilder.cs @@ -14,10 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow { public interface ISaverBuilder diff --git a/src/TensorFlowNET.Core/Train/Saving/ReferenceVariableSaveable.cs b/src/TensorFlowNET.Core/Train/Saving/ReferenceVariableSaveable.cs index fbe9509c..99a1c02b 100644 --- a/src/TensorFlowNET.Core/Train/Saving/ReferenceVariableSaveable.cs +++ b/src/TensorFlowNET.Core/Train/Saving/ReferenceVariableSaveable.cs @@ -14,10 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow { public class ReferenceVariableSaveable : SaveableObject diff --git a/src/TensorFlowNET.Core/Train/Saving/ResourceVariableSaveable.cs b/src/TensorFlowNET.Core/Train/Saving/ResourceVariableSaveable.cs index 7c890e9e..d358f12a 100644 --- a/src/TensorFlowNET.Core/Train/Saving/ResourceVariableSaveable.cs +++ b/src/TensorFlowNET.Core/Train/Saving/ResourceVariableSaveable.cs @@ -14,10 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow { public class ResourceVariableSaveable : SaveableObject diff --git a/src/TensorFlowNET.Core/Train/Saving/SaveSpec.cs b/src/TensorFlowNET.Core/Train/Saving/SaveSpec.cs index 601a022e..1ae912ce 100644 --- a/src/TensorFlowNET.Core/Train/Saving/SaveSpec.cs +++ b/src/TensorFlowNET.Core/Train/Saving/SaveSpec.cs @@ -14,10 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow { /// diff --git a/src/TensorFlowNET.Core/Train/Saving/SaveableObject.cs b/src/TensorFlowNET.Core/Train/Saving/SaveableObject.cs index 17329784..5aa978b1 100644 --- a/src/TensorFlowNET.Core/Train/Saving/SaveableObject.cs +++ b/src/TensorFlowNET.Core/Train/Saving/SaveableObject.cs @@ -14,10 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow { public class SaveableObject diff --git a/src/TensorFlowNET.Core/Train/Saving/Saver.cs b/src/TensorFlowNET.Core/Train/Saving/Saver.cs index 37f5c302..25adcb5b 100644 --- a/src/TensorFlowNET.Core/Train/Saving/Saver.cs +++ b/src/TensorFlowNET.Core/Train/Saving/Saver.cs @@ -18,7 +18,6 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Text; using static Tensorflow.Python; namespace Tensorflow diff --git a/src/TensorFlowNET.Core/Train/Saving/checkpoint_management.py.cs b/src/TensorFlowNET.Core/Train/Saving/checkpoint_management.py.cs index 6cbe6b4c..4ff538db 100644 --- a/src/TensorFlowNET.Core/Train/Saving/checkpoint_management.py.cs +++ b/src/TensorFlowNET.Core/Train/Saving/checkpoint_management.py.cs @@ -18,7 +18,6 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Text; using static Tensorflow.SaverDef.Types; namespace Tensorflow diff --git a/src/TensorFlowNET.Core/Train/Saving/saveable_object_util.py.cs b/src/TensorFlowNET.Core/Train/Saving/saveable_object_util.py.cs index 668aae36..267e7561 100644 --- a/src/TensorFlowNET.Core/Train/Saving/saveable_object_util.py.cs +++ b/src/TensorFlowNET.Core/Train/Saving/saveable_object_util.py.cs @@ -17,7 +17,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; using static Tensorflow.Python; namespace Tensorflow diff --git a/src/TensorFlowNET.Core/Train/Saving/saver.py.cs b/src/TensorFlowNET.Core/Train/Saving/saver.py.cs index 455f4e47..49c9bfc5 100644 --- a/src/TensorFlowNET.Core/Train/Saving/saver.py.cs +++ b/src/TensorFlowNET.Core/Train/Saving/saver.py.cs @@ -17,7 +17,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Train/SlotCreator.cs b/src/TensorFlowNET.Core/Train/SlotCreator.cs index a055084a..aaa2c171 100644 --- a/src/TensorFlowNET.Core/Train/SlotCreator.cs +++ b/src/TensorFlowNET.Core/Train/SlotCreator.cs @@ -15,8 +15,6 @@ ******************************************************************************/ using System; -using System.Collections.Generic; -using System.Text; using Tensorflow.Operations.Initializers; using static Tensorflow.Python; diff --git a/src/TensorFlowNET.Core/Train/Trackable.cs b/src/TensorFlowNET.Core/Train/Trackable.cs index 99096618..a718c869 100644 --- a/src/TensorFlowNET.Core/Train/Trackable.cs +++ b/src/TensorFlowNET.Core/Train/Trackable.cs @@ -15,8 +15,6 @@ ******************************************************************************/ using System; -using System.Collections.Generic; -using System.Text; namespace Tensorflow.Train { diff --git a/src/TensorFlowNET.Core/Train/VariableAggregationType.cs b/src/TensorFlowNET.Core/Train/VariableAggregationType.cs index 4a256ae1..70976b1f 100644 --- a/src/TensorFlowNET.Core/Train/VariableAggregationType.cs +++ b/src/TensorFlowNET.Core/Train/VariableAggregationType.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Tensorflow +namespace Tensorflow { public enum VariableAggregationType { diff --git a/src/TensorFlowNET.Core/Train/_OptimizableVariable.cs b/src/TensorFlowNET.Core/Train/_OptimizableVariable.cs index 2d61781a..86d53fe6 100644 --- a/src/TensorFlowNET.Core/Train/_OptimizableVariable.cs +++ b/src/TensorFlowNET.Core/Train/_OptimizableVariable.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Tensorflow.Framework; - -namespace Tensorflow +namespace Tensorflow { public interface _OptimizableVariable { diff --git a/src/TensorFlowNET.Core/Train/gen_training_ops.py.cs b/src/TensorFlowNET.Core/Train/gen_training_ops.py.cs index 35e56378..7235ce7b 100644 --- a/src/TensorFlowNET.Core/Train/gen_training_ops.py.cs +++ b/src/TensorFlowNET.Core/Train/gen_training_ops.py.cs @@ -14,10 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow { public class gen_training_ops diff --git a/src/TensorFlowNET.Core/Train/optimizer.py.cs b/src/TensorFlowNET.Core/Train/optimizer.py.cs index 39fff271..9f48d161 100644 --- a/src/TensorFlowNET.Core/Train/optimizer.py.cs +++ b/src/TensorFlowNET.Core/Train/optimizer.py.cs @@ -14,9 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; using Tensorflow.Framework; namespace Tensorflow diff --git a/src/TensorFlowNET.Core/Train/tf.optimizers.cs b/src/TensorFlowNET.Core/Train/tf.optimizers.cs index e1802b30..5dee2060 100644 --- a/src/TensorFlowNET.Core/Train/tf.optimizers.cs +++ b/src/TensorFlowNET.Core/Train/tf.optimizers.cs @@ -14,10 +14,7 @@ limitations under the License. ******************************************************************************/ -using System; using System.Collections.Generic; -using System.IO; -using System.Text; using Tensorflow.Train; namespace Tensorflow diff --git a/src/TensorFlowNET.Core/Util/CmdHelper.cs b/src/TensorFlowNET.Core/Util/CmdHelper.cs index d4ed6cb1..13acbcb0 100644 --- a/src/TensorFlowNET.Core/Util/CmdHelper.cs +++ b/src/TensorFlowNET.Core/Util/CmdHelper.cs @@ -15,11 +15,7 @@ ******************************************************************************/ using System; -using System.Collections.Generic; using System.Diagnostics; -using System.IO; -using System.Text; -using System.Threading; namespace Tensorflow.Util { diff --git a/src/TensorFlowNET.Core/Variables/PureVariableScope.cs b/src/TensorFlowNET.Core/Variables/PureVariableScope.cs index cdbc1d6a..b6cd2add 100644 --- a/src/TensorFlowNET.Core/Variables/PureVariableScope.cs +++ b/src/TensorFlowNET.Core/Variables/PureVariableScope.cs @@ -14,10 +14,8 @@ limitations under the License. ******************************************************************************/ -using System; using System.Collections.Generic; using System.Linq; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Variables/RefVariable.Implicit.cs b/src/TensorFlowNET.Core/Variables/RefVariable.Implicit.cs index 5e7fe2a5..864dc8c4 100644 --- a/src/TensorFlowNET.Core/Variables/RefVariable.Implicit.cs +++ b/src/TensorFlowNET.Core/Variables/RefVariable.Implicit.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Tensorflow +namespace Tensorflow { public partial class RefVariable { diff --git a/src/TensorFlowNET.Core/Variables/RefVariable.Operators.cs b/src/TensorFlowNET.Core/Variables/RefVariable.Operators.cs index 2ea6b91d..8c2c1204 100644 --- a/src/TensorFlowNET.Core/Variables/RefVariable.Operators.cs +++ b/src/TensorFlowNET.Core/Variables/RefVariable.Operators.cs @@ -14,9 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; using static Tensorflow.Python; namespace Tensorflow diff --git a/src/TensorFlowNET.Core/Variables/RefVariable.cs b/src/TensorFlowNET.Core/Variables/RefVariable.cs index df30d042..d380975e 100644 --- a/src/TensorFlowNET.Core/Variables/RefVariable.cs +++ b/src/TensorFlowNET.Core/Variables/RefVariable.cs @@ -15,11 +15,8 @@ ******************************************************************************/ using Google.Protobuf; -using Google.Protobuf.Collections; using System; using System.Collections.Generic; -using System.Linq; -using System.Text; using static Tensorflow.Python; namespace Tensorflow diff --git a/src/TensorFlowNET.Core/Variables/ResourceVariable.cs b/src/TensorFlowNET.Core/Variables/ResourceVariable.cs index 5a7491c5..85d2ca56 100644 --- a/src/TensorFlowNET.Core/Variables/ResourceVariable.cs +++ b/src/TensorFlowNET.Core/Variables/ResourceVariable.cs @@ -16,7 +16,6 @@ using System; using System.Collections.Generic; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Variables/VariableScope.cs b/src/TensorFlowNET.Core/Variables/VariableScope.cs index 02a7b2d7..d509d6b2 100644 --- a/src/TensorFlowNET.Core/Variables/VariableScope.cs +++ b/src/TensorFlowNET.Core/Variables/VariableScope.cs @@ -14,9 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; using static Tensorflow.Python; namespace Tensorflow diff --git a/src/TensorFlowNET.Core/Variables/VariableV1.cs b/src/TensorFlowNET.Core/Variables/VariableV1.cs index a222c67f..eb3349fd 100644 --- a/src/TensorFlowNET.Core/Variables/VariableV1.cs +++ b/src/TensorFlowNET.Core/Variables/VariableV1.cs @@ -14,10 +14,7 @@ limitations under the License. ******************************************************************************/ -using System; using System.Collections.Generic; -using System.Text; -using static Tensorflow.Python; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Variables/_ReuseMode.cs b/src/TensorFlowNET.Core/Variables/_ReuseMode.cs index f2717310..e63e51f7 100644 --- a/src/TensorFlowNET.Core/Variables/_ReuseMode.cs +++ b/src/TensorFlowNET.Core/Variables/_ReuseMode.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Tensorflow +namespace Tensorflow { /// /// Mode for variable access within a variable scope. diff --git a/src/TensorFlowNET.Core/Variables/_VariableScopeStore.cs b/src/TensorFlowNET.Core/Variables/_VariableScopeStore.cs index 0bea062a..083afe4f 100644 --- a/src/TensorFlowNET.Core/Variables/_VariableScopeStore.cs +++ b/src/TensorFlowNET.Core/Variables/_VariableScopeStore.cs @@ -14,9 +14,7 @@ limitations under the License. ******************************************************************************/ -using System; using System.Collections.Generic; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Variables/_VariableStore.cs b/src/TensorFlowNET.Core/Variables/_VariableStore.cs index 69ea7b01..46212a62 100644 --- a/src/TensorFlowNET.Core/Variables/_VariableStore.cs +++ b/src/TensorFlowNET.Core/Variables/_VariableStore.cs @@ -16,7 +16,6 @@ using System; using System.Collections.Generic; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Variables/gen_state_ops.py.cs b/src/TensorFlowNET.Core/Variables/gen_state_ops.py.cs index 0314e11f..e1ab9e20 100644 --- a/src/TensorFlowNET.Core/Variables/gen_state_ops.py.cs +++ b/src/TensorFlowNET.Core/Variables/gen_state_ops.py.cs @@ -14,9 +14,7 @@ limitations under the License. ******************************************************************************/ -using System; using System.Collections.Generic; -using System.Text; using Tensorflow.Eager; namespace Tensorflow diff --git a/src/TensorFlowNET.Core/Variables/state_ops.cs b/src/TensorFlowNET.Core/Variables/state_ops.cs index bc96d1f5..e89844f9 100644 --- a/src/TensorFlowNET.Core/Variables/state_ops.cs +++ b/src/TensorFlowNET.Core/Variables/state_ops.cs @@ -15,8 +15,6 @@ ******************************************************************************/ using System; -using System.Collections.Generic; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Variables/variable_scope.py.cs b/src/TensorFlowNET.Core/Variables/variable_scope.py.cs index 11bc7d3d..9a658c77 100644 --- a/src/TensorFlowNET.Core/Variables/variable_scope.py.cs +++ b/src/TensorFlowNET.Core/Variables/variable_scope.py.cs @@ -17,7 +17,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Variables/variables.py.cs b/src/TensorFlowNET.Core/Variables/variables.py.cs index df681f78..3880bc7f 100644 --- a/src/TensorFlowNET.Core/Variables/variables.py.cs +++ b/src/TensorFlowNET.Core/Variables/variables.py.cs @@ -17,7 +17,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/WeakKeyDicionary.cs b/src/TensorFlowNET.Core/WeakKeyDicionary.cs index 79b2ec22..c6504282 100644 --- a/src/TensorFlowNET.Core/WeakKeyDicionary.cs +++ b/src/TensorFlowNET.Core/WeakKeyDicionary.cs @@ -17,9 +17,7 @@ using System; using System.Collections; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Text; -using System.Runtime.InteropServices; +using System.Diagnostics.CodeAnalysis; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/ops.GraphKeys.cs b/src/TensorFlowNET.Core/ops.GraphKeys.cs index d55907ad..94e1b8d5 100644 --- a/src/TensorFlowNET.Core/ops.GraphKeys.cs +++ b/src/TensorFlowNET.Core/ops.GraphKeys.cs @@ -14,10 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; - namespace Tensorflow { public partial class ops diff --git a/src/TensorFlowNET.Core/ops._DefaultStack.cs b/src/TensorFlowNET.Core/ops._DefaultStack.cs index 45c9b1e5..ecdd8d9b 100644 --- a/src/TensorFlowNET.Core/ops._DefaultStack.cs +++ b/src/TensorFlowNET.Core/ops._DefaultStack.cs @@ -16,7 +16,6 @@ using System; using System.Collections.Generic; -using System.Text; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/ops.name_scope.cs b/src/TensorFlowNET.Core/ops.name_scope.cs index 913d5c34..7096c6ad 100644 --- a/src/TensorFlowNET.Core/ops.name_scope.cs +++ b/src/TensorFlowNET.Core/ops.name_scope.cs @@ -14,11 +14,7 @@ limitations under the License. ******************************************************************************/ -using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using Tensorflow.Eager; namespace Tensorflow { @@ -36,22 +32,19 @@ namespace Tensorflow public string _name; public string _default_name; public object _values; - public Context _ctx; public string _name_scope; public string old_stack = ""; - private object _g_manager; - + public NameScope(string name, string default_name = "", object values = null) { _name = name; _default_name = default_name; _values = values; - // _ctx = new Context(); } public void __enter__() { - _name = _name == null ? _default_name : _name; + _name = _name ?? _default_name; Graph g = null; @@ -71,12 +64,10 @@ namespace Tensorflow { var g = get_default_graph(); g._name_stack = old_stack; - // Console.WriteLine($"name_scope: {g._name_stack} -> {old_stack}"); } public void __exit__() { - } /// diff --git a/src/TensorFlowNET.Core/ops.py.cs b/src/TensorFlowNET.Core/ops.py.cs index 93d55975..90cda74e 100644 --- a/src/TensorFlowNET.Core/ops.py.cs +++ b/src/TensorFlowNET.Core/ops.py.cs @@ -17,13 +17,9 @@ using System; using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Text; -using System.Threading; -using Tensorflow; using Google.Protobuf; using System.Linq; using NumSharp; -using System.ComponentModel; using static Tensorflow.Python; namespace Tensorflow diff --git a/src/TensorFlowNET.Core/tf.cs b/src/TensorFlowNET.Core/tf.cs index 9959a3a7..87cedc59 100644 --- a/src/TensorFlowNET.Core/tf.cs +++ b/src/TensorFlowNET.Core/tf.cs @@ -14,11 +14,7 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; using Tensorflow.Eager; -using static Tensorflow.ops; namespace Tensorflow { diff --git a/test/KerasNET.Example/Program.cs b/test/KerasNET.Example/Program.cs index 2fbf288c..f85fe127 100644 --- a/test/KerasNET.Example/Program.cs +++ b/test/KerasNET.Example/Program.cs @@ -1,13 +1,7 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using Tensorflow; -using static Tensorflow.Python; -using static Keras.Keras; using Keras.Layers; -using Keras; using NumSharp; namespace Keras.Example diff --git a/test/KerasNET.Test/BaseTests.cs b/test/KerasNET.Test/BaseTests.cs index 92c777a0..05cde48c 100644 --- a/test/KerasNET.Test/BaseTests.cs +++ b/test/KerasNET.Test/BaseTests.cs @@ -1,6 +1,4 @@ -using System; -using Tensorflow; -using Keras; +using Tensorflow; using Keras.Layers; using NumSharp; using Microsoft.VisualStudio.TestTools.UnitTesting; diff --git a/test/TensorFlowNET.Examples/BasicEagerApi.cs b/test/TensorFlowNET.Examples/BasicEagerApi.cs index 8844e17a..ab2d1f8a 100644 --- a/test/TensorFlowNET.Examples/BasicEagerApi.cs +++ b/test/TensorFlowNET.Examples/BasicEagerApi.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; using Tensorflow; namespace TensorFlowNET.Examples diff --git a/test/TensorFlowNET.Examples/BasicModels/KMeansClustering.cs b/test/TensorFlowNET.Examples/BasicModels/KMeansClustering.cs index 085a92e0..c0ca95b3 100644 --- a/test/TensorFlowNET.Examples/BasicModels/KMeansClustering.cs +++ b/test/TensorFlowNET.Examples/BasicModels/KMeansClustering.cs @@ -16,12 +16,8 @@ using NumSharp; using System; -using System.Collections.Generic; using System.Diagnostics; -using System.Linq; -using System.Text; using Tensorflow; -using Tensorflow.Clustering; using TensorFlowNET.Examples.Utility; using static Tensorflow.Python; diff --git a/test/TensorFlowNET.Examples/BasicModels/LinearRegression.cs b/test/TensorFlowNET.Examples/BasicModels/LinearRegression.cs index 96c5c6b4..f7baef1d 100644 --- a/test/TensorFlowNET.Examples/BasicModels/LinearRegression.cs +++ b/test/TensorFlowNET.Examples/BasicModels/LinearRegression.cs @@ -16,8 +16,6 @@ using NumSharp; using System; -using System.Collections.Generic; -using System.Text; using Tensorflow; using static Tensorflow.Python; diff --git a/test/TensorFlowNET.Examples/BasicModels/LogisticRegression.cs b/test/TensorFlowNET.Examples/BasicModels/LogisticRegression.cs index d23e7872..185dd1fe 100644 --- a/test/TensorFlowNET.Examples/BasicModels/LogisticRegression.cs +++ b/test/TensorFlowNET.Examples/BasicModels/LogisticRegression.cs @@ -16,11 +16,8 @@ using NumSharp; using System; -using System.Collections.Generic; using System.Diagnostics; using System.IO; -using System.Linq; -using System.Text; using Tensorflow; using TensorFlowNET.Examples.Utility; using static Tensorflow.Python; diff --git a/test/TensorFlowNET.Examples/BasicModels/NaiveBayesClassifier.cs b/test/TensorFlowNET.Examples/BasicModels/NaiveBayesClassifier.cs index ef92055f..d77c6902 100644 --- a/test/TensorFlowNET.Examples/BasicModels/NaiveBayesClassifier.cs +++ b/test/TensorFlowNET.Examples/BasicModels/NaiveBayesClassifier.cs @@ -16,10 +16,8 @@ using System; using System.Collections.Generic; -using System.Text; using Tensorflow; using NumSharp; -using System.Linq; using static Tensorflow.Python; using System.IO; using TensorFlowNET.Examples.Utility; diff --git a/test/TensorFlowNET.Examples/BasicModels/NearestNeighbor.cs b/test/TensorFlowNET.Examples/BasicModels/NearestNeighbor.cs index e784eeeb..86ecd281 100644 --- a/test/TensorFlowNET.Examples/BasicModels/NearestNeighbor.cs +++ b/test/TensorFlowNET.Examples/BasicModels/NearestNeighbor.cs @@ -16,8 +16,6 @@ using NumSharp; using System; -using System.Collections.Generic; -using System.Text; using Tensorflow; using TensorFlowNET.Examples.Utility; using static Tensorflow.Python; diff --git a/test/TensorFlowNET.Examples/BasicModels/NeuralNetXor.cs b/test/TensorFlowNET.Examples/BasicModels/NeuralNetXor.cs index 1aa65541..a4a2901c 100644 --- a/test/TensorFlowNET.Examples/BasicModels/NeuralNetXor.cs +++ b/test/TensorFlowNET.Examples/BasicModels/NeuralNetXor.cs @@ -15,8 +15,6 @@ ******************************************************************************/ using System; -using System.Collections.Generic; -using System.Text; using NumSharp; using Tensorflow; using TensorFlowNET.Examples.Utility; diff --git a/test/TensorFlowNET.Examples/BasicOperations.cs b/test/TensorFlowNET.Examples/BasicOperations.cs index 8176fb0f..5fd52e2d 100644 --- a/test/TensorFlowNET.Examples/BasicOperations.cs +++ b/test/TensorFlowNET.Examples/BasicOperations.cs @@ -1,7 +1,5 @@ using NumSharp; using System; -using System.Collections.Generic; -using System.Text; using Tensorflow; using static Tensorflow.Python; diff --git a/test/TensorFlowNET.Examples/HelloWorld.cs b/test/TensorFlowNET.Examples/HelloWorld.cs index b6973503..e9c91336 100644 --- a/test/TensorFlowNET.Examples/HelloWorld.cs +++ b/test/TensorFlowNET.Examples/HelloWorld.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; using Tensorflow; using static Tensorflow.Python; diff --git a/test/TensorFlowNET.Examples/IExample.cs b/test/TensorFlowNET.Examples/IExample.cs index d9826bae..f8cda9b9 100644 --- a/test/TensorFlowNET.Examples/IExample.cs +++ b/test/TensorFlowNET.Examples/IExample.cs @@ -14,9 +14,6 @@ limitations under the License. ******************************************************************************/ -using System; -using System.Collections.Generic; -using System.Text; using Tensorflow; namespace TensorFlowNET.Examples diff --git a/test/TensorFlowNET.Examples/ImageProcessing/DigitRecognitionCNN.cs b/test/TensorFlowNET.Examples/ImageProcessing/DigitRecognitionCNN.cs index cb6d7898..25ffc46a 100644 --- a/test/TensorFlowNET.Examples/ImageProcessing/DigitRecognitionCNN.cs +++ b/test/TensorFlowNET.Examples/ImageProcessing/DigitRecognitionCNN.cs @@ -16,8 +16,6 @@ using NumSharp; using System; -using System.Collections.Generic; -using System.Text; using Tensorflow; using TensorFlowNET.Examples.Utility; using static Tensorflow.Python; diff --git a/test/TensorFlowNET.Examples/ImageProcessing/DigitRecognitionNN.cs b/test/TensorFlowNET.Examples/ImageProcessing/DigitRecognitionNN.cs index a719a2d7..09fdc818 100644 --- a/test/TensorFlowNET.Examples/ImageProcessing/DigitRecognitionNN.cs +++ b/test/TensorFlowNET.Examples/ImageProcessing/DigitRecognitionNN.cs @@ -16,8 +16,6 @@ using NumSharp; using System; -using System.Collections.Generic; -using System.Text; using Tensorflow; using TensorFlowNET.Examples.Utility; using static Tensorflow.Python; diff --git a/test/TensorFlowNET.Examples/ImageProcessing/DigitRecognitionRNN.cs b/test/TensorFlowNET.Examples/ImageProcessing/DigitRecognitionRNN.cs index 2e9160af..796d6103 100644 --- a/test/TensorFlowNET.Examples/ImageProcessing/DigitRecognitionRNN.cs +++ b/test/TensorFlowNET.Examples/ImageProcessing/DigitRecognitionRNN.cs @@ -16,8 +16,6 @@ using NumSharp; using System; -using System.Collections.Generic; -using System.Text; using Tensorflow; using TensorFlowNET.Examples.Utility; using static Tensorflow.Python; diff --git a/test/TensorFlowNET.Examples/ImageProcessing/ImageBackgroundRemoval.cs b/test/TensorFlowNET.Examples/ImageProcessing/ImageBackgroundRemoval.cs index 46f6b6bf..c43c853a 100644 --- a/test/TensorFlowNET.Examples/ImageProcessing/ImageBackgroundRemoval.cs +++ b/test/TensorFlowNET.Examples/ImageProcessing/ImageBackgroundRemoval.cs @@ -1,7 +1,5 @@ using System; -using System.Collections.Generic; using System.IO; -using System.Text; using Tensorflow; using TensorFlowNET.Examples.Utility; using static Tensorflow.Python; diff --git a/test/TensorFlowNET.Examples/ImageProcessing/ImageRecognitionInception.cs b/test/TensorFlowNET.Examples/ImageProcessing/ImageRecognitionInception.cs index ec6e06e7..a0f61029 100644 --- a/test/TensorFlowNET.Examples/ImageProcessing/ImageRecognitionInception.cs +++ b/test/TensorFlowNET.Examples/ImageProcessing/ImageRecognitionInception.cs @@ -4,9 +4,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; using Console = Colorful.Console; -using System.Linq; -using System.Net; -using System.Text; using Tensorflow; using System.Drawing; using static Tensorflow.Python; diff --git a/test/TensorFlowNET.Examples/ImageProcessing/InceptionArchGoogLeNet.cs b/test/TensorFlowNET.Examples/ImageProcessing/InceptionArchGoogLeNet.cs index 985d855d..2f6b9ab1 100644 --- a/test/TensorFlowNET.Examples/ImageProcessing/InceptionArchGoogLeNet.cs +++ b/test/TensorFlowNET.Examples/ImageProcessing/InceptionArchGoogLeNet.cs @@ -1,14 +1,7 @@ -using ICSharpCode.SharpZipLib.GZip; -using ICSharpCode.SharpZipLib.Tar; -using NumSharp; +using NumSharp; using System; -using System.Collections.Generic; using System.IO; using System.Linq; -using System.Net; -using System.Text; -using System.Threading; -using System.Threading.Tasks; using Tensorflow; using static Tensorflow.Python; diff --git a/test/TensorFlowNET.Examples/ImageProcessing/ObjectDetection.cs b/test/TensorFlowNET.Examples/ImageProcessing/ObjectDetection.cs index 9c4760d7..f40be91f 100644 --- a/test/TensorFlowNET.Examples/ImageProcessing/ObjectDetection.cs +++ b/test/TensorFlowNET.Examples/ImageProcessing/ObjectDetection.cs @@ -16,9 +16,7 @@ using NumSharp; using System; -using System.Collections.Generic; using System.IO; -using System.Text; using Tensorflow; using TensorFlowNET.Examples.Utility; using System.Drawing; diff --git a/test/TensorFlowNET.Examples/ImageProcessing/RetrainImageClassifier.cs b/test/TensorFlowNET.Examples/ImageProcessing/RetrainImageClassifier.cs index fab83d8a..628a7b5c 100644 --- a/test/TensorFlowNET.Examples/ImageProcessing/RetrainImageClassifier.cs +++ b/test/TensorFlowNET.Examples/ImageProcessing/RetrainImageClassifier.cs @@ -19,14 +19,11 @@ using NumSharp; using System; using System.Collections.Generic; using System.Diagnostics; -using System.Drawing; using System.IO; using System.Linq; -using System.Text; using Tensorflow; using TensorFlowNET.Examples.Utility; using static Tensorflow.Python; -using Console = Colorful.Console; namespace TensorFlowNET.Examples.ImageProcess { diff --git a/test/TensorFlowNET.Examples/TextProcessing/BinaryTextClassification.cs b/test/TensorFlowNET.Examples/TextProcessing/BinaryTextClassification.cs index 791c17b8..e0c886a9 100644 --- a/test/TensorFlowNET.Examples/TextProcessing/BinaryTextClassification.cs +++ b/test/TensorFlowNET.Examples/TextProcessing/BinaryTextClassification.cs @@ -4,9 +4,7 @@ using System.IO; using Tensorflow; using Newtonsoft.Json; using System.Linq; -using System.Text.RegularExpressions; using NumSharp; -using static Tensorflow.Python; namespace TensorFlowNET.Examples { diff --git a/test/TensorFlowNET.Examples/TextProcessing/CnnTextClassification.cs b/test/TensorFlowNET.Examples/TextProcessing/CnnTextClassification.cs index cf52618e..a2afe43d 100644 --- a/test/TensorFlowNET.Examples/TextProcessing/CnnTextClassification.cs +++ b/test/TensorFlowNET.Examples/TextProcessing/CnnTextClassification.cs @@ -15,13 +15,10 @@ ******************************************************************************/ using System; -using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; -using System.Text; -using Newtonsoft.Json; using NumSharp; using Tensorflow; using Tensorflow.Sessions; diff --git a/test/TensorFlowNET.Examples/TextProcessing/NER/BiLstmCrfNer.cs b/test/TensorFlowNET.Examples/TextProcessing/NER/BiLstmCrfNer.cs index 1a96d24c..18c6e46f 100644 --- a/test/TensorFlowNET.Examples/TextProcessing/NER/BiLstmCrfNer.cs +++ b/test/TensorFlowNET.Examples/TextProcessing/NER/BiLstmCrfNer.cs @@ -1,10 +1,7 @@ using System; -using System.Collections.Generic; using System.IO; -using System.Text; using Tensorflow; using Tensorflow.Estimator; -using static Tensorflow.Python; namespace TensorFlowNET.Examples { diff --git a/test/TensorFlowNET.Examples/TextProcessing/NER/CRF.cs b/test/TensorFlowNET.Examples/TextProcessing/NER/CRF.cs index bb23c664..7819dcef 100644 --- a/test/TensorFlowNET.Examples/TextProcessing/NER/CRF.cs +++ b/test/TensorFlowNET.Examples/TextProcessing/NER/CRF.cs @@ -1,8 +1,5 @@ using System; -using System.Collections.Generic; -using System.Text; using Tensorflow; -using static Tensorflow.Python; namespace TensorFlowNET.Examples { diff --git a/test/TensorFlowNET.Examples/TextProcessing/NER/LstmCrfNer.cs b/test/TensorFlowNET.Examples/TextProcessing/NER/LstmCrfNer.cs index 0cf75d2e..2ec703ba 100644 --- a/test/TensorFlowNET.Examples/TextProcessing/NER/LstmCrfNer.cs +++ b/test/TensorFlowNET.Examples/TextProcessing/NER/LstmCrfNer.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Text; using Tensorflow; using Tensorflow.Estimator; using TensorFlowNET.Examples.Utility; diff --git a/test/TensorFlowNET.Examples/TextProcessing/NamedEntityRecognition.cs b/test/TensorFlowNET.Examples/TextProcessing/NamedEntityRecognition.cs index 10615e03..157677ea 100644 --- a/test/TensorFlowNET.Examples/TextProcessing/NamedEntityRecognition.cs +++ b/test/TensorFlowNET.Examples/TextProcessing/NamedEntityRecognition.cs @@ -1,8 +1,5 @@ using System; -using System.Collections.Generic; -using System.Text; using Tensorflow; -using static Tensorflow.Python; namespace TensorFlowNET.Examples { diff --git a/test/TensorFlowNET.Examples/TextProcessing/Word2Vec.cs b/test/TensorFlowNET.Examples/TextProcessing/Word2Vec.cs index a30912be..ce6628e3 100644 --- a/test/TensorFlowNET.Examples/TextProcessing/Word2Vec.cs +++ b/test/TensorFlowNET.Examples/TextProcessing/Word2Vec.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Text; using Tensorflow; using TensorFlowNET.Examples.Utility; using static Tensorflow.Python; diff --git a/test/TensorFlowNET.Examples/TextProcessing/cnn_models/CharCnn.cs b/test/TensorFlowNET.Examples/TextProcessing/cnn_models/CharCnn.cs index 43097b5b..390c6040 100644 --- a/test/TensorFlowNET.Examples/TextProcessing/cnn_models/CharCnn.cs +++ b/test/TensorFlowNET.Examples/TextProcessing/cnn_models/CharCnn.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Tensorflow; +using Tensorflow; using static Tensorflow.Python; namespace TensorFlowNET.Examples.Text diff --git a/test/TensorFlowNET.Examples/TextProcessing/cnn_models/ITextModel.cs b/test/TensorFlowNET.Examples/TextProcessing/cnn_models/ITextModel.cs index ab4bb372..dd5a8704 100644 --- a/test/TensorFlowNET.Examples/TextProcessing/cnn_models/ITextModel.cs +++ b/test/TensorFlowNET.Examples/TextProcessing/cnn_models/ITextModel.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Tensorflow; - -namespace TensorFlowNET.Examples.Text +namespace TensorFlowNET.Examples.Text { interface ITextModel { diff --git a/test/TensorFlowNET.Examples/TextProcessing/cnn_models/VdCnn.cs b/test/TensorFlowNET.Examples/TextProcessing/cnn_models/VdCnn.cs index 06852faf..c71376f8 100644 --- a/test/TensorFlowNET.Examples/TextProcessing/cnn_models/VdCnn.cs +++ b/test/TensorFlowNET.Examples/TextProcessing/cnn_models/VdCnn.cs @@ -1,7 +1,5 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; -using System.Text; using Tensorflow; using static Tensorflow.Python; diff --git a/test/TensorFlowNET.Examples/TextProcessing/cnn_models/WordCnn.cs b/test/TensorFlowNET.Examples/TextProcessing/cnn_models/WordCnn.cs index 749ec333..b51f6719 100644 --- a/test/TensorFlowNET.Examples/TextProcessing/cnn_models/WordCnn.cs +++ b/test/TensorFlowNET.Examples/TextProcessing/cnn_models/WordCnn.cs @@ -14,10 +14,7 @@ limitations under the License. ******************************************************************************/ -using System; using System.Collections.Generic; -using System.Linq; -using System.Text; using Tensorflow; using static Tensorflow.Python; diff --git a/test/TensorFlowNET.Examples/Utility/ArrayShuffling.cs b/test/TensorFlowNET.Examples/Utility/ArrayShuffling.cs index 6620623b..2ae3e2ea 100644 --- a/test/TensorFlowNET.Examples/Utility/ArrayShuffling.cs +++ b/test/TensorFlowNET.Examples/Utility/ArrayShuffling.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; namespace TensorFlowNET.Examples.Utility { diff --git a/test/TensorFlowNET.Examples/Utility/CoNLLDataset.cs b/test/TensorFlowNET.Examples/Utility/CoNLLDataset.cs index 9b50bfd6..14b96656 100644 --- a/test/TensorFlowNET.Examples/Utility/CoNLLDataset.cs +++ b/test/TensorFlowNET.Examples/Utility/CoNLLDataset.cs @@ -1,9 +1,6 @@ -using System; -using System.Collections; -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; using System.Linq; -using System.Text; using Tensorflow.Estimator; namespace TensorFlowNET.Examples.Utility diff --git a/test/TensorFlowNET.Examples/Utility/DataSetMnist.cs b/test/TensorFlowNET.Examples/Utility/DataSetMnist.cs index 0825a702..0017eba5 100644 --- a/test/TensorFlowNET.Examples/Utility/DataSetMnist.cs +++ b/test/TensorFlowNET.Examples/Utility/DataSetMnist.cs @@ -15,9 +15,6 @@ ******************************************************************************/ using NumSharp; -using System; -using System.Collections.Generic; -using System.Text; using Tensorflow; namespace TensorFlowNET.Examples.Utility diff --git a/test/TensorFlowNET.Examples/Utility/Datasets.cs b/test/TensorFlowNET.Examples/Utility/Datasets.cs index af57c7cf..0c8c4e2d 100644 --- a/test/TensorFlowNET.Examples/Utility/Datasets.cs +++ b/test/TensorFlowNET.Examples/Utility/Datasets.cs @@ -1,7 +1,4 @@ using NumSharp; -using System; -using System.Collections.Generic; -using System.Text; namespace TensorFlowNET.Examples.Utility { diff --git a/test/TensorFlowNET.Examples/Utility/IDataSet.cs b/test/TensorFlowNET.Examples/Utility/IDataSet.cs index 2815bf11..31be57c1 100644 --- a/test/TensorFlowNET.Examples/Utility/IDataSet.cs +++ b/test/TensorFlowNET.Examples/Utility/IDataSet.cs @@ -1,7 +1,4 @@ using NumSharp; -using System; -using System.Collections.Generic; -using System.Text; namespace TensorFlowNET.Examples.Utility { diff --git a/test/TensorFlowNET.Examples/Utility/MNIST.cs b/test/TensorFlowNET.Examples/Utility/MNIST.cs index 2a61fe77..73d6fe2a 100644 --- a/test/TensorFlowNET.Examples/Utility/MNIST.cs +++ b/test/TensorFlowNET.Examples/Utility/MNIST.cs @@ -16,10 +16,7 @@ using NumSharp; using System; -using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Text; using Tensorflow; namespace TensorFlowNET.Examples.Utility diff --git a/test/TensorFlowNET.Examples/Utility/PbtxtParser.cs b/test/TensorFlowNET.Examples/Utility/PbtxtParser.cs index cb5857f3..4a918017 100644 --- a/test/TensorFlowNET.Examples/Utility/PbtxtParser.cs +++ b/test/TensorFlowNET.Examples/Utility/PbtxtParser.cs @@ -15,9 +15,7 @@ ******************************************************************************/ using Newtonsoft.Json; -using System; using System.Collections.Generic; -using System.Text; namespace TensorFlowNET.Examples.Utility { diff --git a/test/TensorFlowNET.Examples/Utility/Web.cs b/test/TensorFlowNET.Examples/Utility/Web.cs index 95e2c762..8f300167 100644 --- a/test/TensorFlowNET.Examples/Utility/Web.cs +++ b/test/TensorFlowNET.Examples/Utility/Web.cs @@ -15,11 +15,9 @@ ******************************************************************************/ using System; -using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; -using System.Text; using System.Threading; using System.Threading.Tasks; diff --git a/test/TensorFlowNET.UnitTest/CApiAttributesTestcs.cs b/test/TensorFlowNET.UnitTest/CApiAttributesTestcs.cs index 857ba94a..7662785d 100644 --- a/test/TensorFlowNET.UnitTest/CApiAttributesTestcs.cs +++ b/test/TensorFlowNET.UnitTest/CApiAttributesTestcs.cs @@ -1,8 +1,5 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using System; -using System.Collections.Generic; -using System.Runtime.InteropServices; -using System.Text; using Tensorflow; namespace TensorFlowNET.UnitTest diff --git a/test/TensorFlowNET.UnitTest/CApiColocationTest.cs b/test/TensorFlowNET.UnitTest/CApiColocationTest.cs index 38e0f32b..6a5b2c0a 100644 --- a/test/TensorFlowNET.UnitTest/CApiColocationTest.cs +++ b/test/TensorFlowNET.UnitTest/CApiColocationTest.cs @@ -1,8 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using System; -using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Text; using Tensorflow; namespace TensorFlowNET.UnitTest diff --git a/test/TensorFlowNET.UnitTest/CApiGradientsTest.cs b/test/TensorFlowNET.UnitTest/CApiGradientsTest.cs index a1928f1f..33e38870 100644 --- a/test/TensorFlowNET.UnitTest/CApiGradientsTest.cs +++ b/test/TensorFlowNET.UnitTest/CApiGradientsTest.cs @@ -1,10 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using NumSharp; using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text; using Tensorflow; using Buffer = Tensorflow.Buffer; diff --git a/test/TensorFlowNET.UnitTest/CApiTest.cs b/test/TensorFlowNET.UnitTest/CApiTest.cs index 2f2888b2..c3cdf227 100644 --- a/test/TensorFlowNET.UnitTest/CApiTest.cs +++ b/test/TensorFlowNET.UnitTest/CApiTest.cs @@ -1,9 +1,5 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using System.Collections.Generic; -using System.Text; using Tensorflow; -using static Tensorflow.Python; namespace TensorFlowNET.UnitTest { diff --git a/test/TensorFlowNET.UnitTest/CSession.cs b/test/TensorFlowNET.UnitTest/CSession.cs index ce5bfc55..33e88286 100644 --- a/test/TensorFlowNET.UnitTest/CSession.cs +++ b/test/TensorFlowNET.UnitTest/CSession.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Runtime.InteropServices; -using System.Text; using Tensorflow; namespace TensorFlowNET.UnitTest diff --git a/test/TensorFlowNET.UnitTest/ConstantTest.cs b/test/TensorFlowNET.UnitTest/ConstantTest.cs index 9052b1b4..7d184619 100644 --- a/test/TensorFlowNET.UnitTest/ConstantTest.cs +++ b/test/TensorFlowNET.UnitTest/ConstantTest.cs @@ -1,10 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using NumSharp; -using System; -using System.Collections.Generic; using System.Linq; -using System.Runtime.InteropServices; -using System.Text; using Tensorflow; using static Tensorflow.Python; @@ -23,6 +19,62 @@ namespace TensorFlowNET.UnitTest var tensor3 = tf.constant(6.0); // double } + [DataTestMethod] + [DataRow(int.MinValue)] + [DataRow(-1)] + [DataRow(0)] + [DataRow(1)] + [DataRow(int.MaxValue)] + public void ScalarConstTypecast_int(int value) + { + var tensor = (Tensor)value; + with(tf.Session(), sess => + { + var result = sess.run(tensor); + Assert.AreEqual(result.Data()[0], value); + }); + } + + [DataTestMethod] + [DataRow(double.NegativeInfinity)] + [DataRow(double.MinValue)] + [DataRow(-1d)] + [DataRow(0d)] + [DataRow(double.Epsilon)] + [DataRow(1d)] + [DataRow(double.MaxValue)] + [DataRow(double.PositiveInfinity)] + [DataRow(double.NaN)] + public void ScalarConstTypecast_double(double value) + { + var tensor = (Tensor)value; + with(tf.Session(), sess => + { + var result = sess.run(tensor); + Assert.AreEqual(result.Data()[0], value); + }); + } + + [DataTestMethod] + [DataRow(float.NegativeInfinity)] + [DataRow(float.MinValue)] + [DataRow(-1f)] + [DataRow(0f)] + [DataRow(float.Epsilon)] + [DataRow(1f)] + [DataRow(float.MaxValue)] + [DataRow(float.PositiveInfinity)] + [DataRow(float.NaN)] + public void ScalarConstTypecast_float(float value) + { + var tensor = (Tensor)value; + with(tf.Session(), sess => + { + var result = sess.run(tensor); + Assert.AreEqual(result.Data()[0], value); + }); + } + [TestMethod] public void StringConst() { @@ -65,6 +117,35 @@ namespace TensorFlowNET.UnitTest }); } + [TestMethod] + public void OnesConst() + { + var ones = tf.ones(new Shape(3, 2), TF_DataType.TF_DOUBLE, "ones"); + with(tf.Session(), sess => + { + var result = sess.run(ones); + + Assert.AreEqual(result.shape[0], 3); + Assert.AreEqual(result.shape[1], 2); + Assert.IsTrue(new[] { 1, 1, 1, 1, 1, 1 }.SequenceEqual(result.Data())); + }); + } + + [TestMethod] + public void OnesToHalves() + { + var ones = tf.ones(new Shape(3, 2), TF_DataType.TF_DOUBLE, "ones"); + var halfes = ones * 0.5; + with(tf.Session(), sess => + { + var result = sess.run(halfes); + + Assert.AreEqual(result.shape[0], 3); + Assert.AreEqual(result.shape[1], 2); + Assert.IsTrue(new[] { .5, .5, .5, .5, .5, .5 }.SequenceEqual(result.Data())); + }); + } + [TestMethod] public void NDimConst() { diff --git a/test/TensorFlowNET.UnitTest/ConsumersTest.cs b/test/TensorFlowNET.UnitTest/ConsumersTest.cs index 436daa71..a310fbc9 100644 --- a/test/TensorFlowNET.UnitTest/ConsumersTest.cs +++ b/test/TensorFlowNET.UnitTest/ConsumersTest.cs @@ -1,7 +1,4 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using System.Collections.Generic; -using System.Text; using Tensorflow; namespace TensorFlowNET.UnitTest diff --git a/test/TensorFlowNET.UnitTest/Eager/CApiVariableTest.cs b/test/TensorFlowNET.UnitTest/Eager/CApiVariableTest.cs index 6e8976b6..8eed6a8f 100644 --- a/test/TensorFlowNET.UnitTest/Eager/CApiVariableTest.cs +++ b/test/TensorFlowNET.UnitTest/Eager/CApiVariableTest.cs @@ -1,7 +1,5 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using System; -using System.Collections.Generic; -using System.Text; using Tensorflow; using Tensorflow.Eager; diff --git a/test/TensorFlowNET.UnitTest/ExamplesTests/ExamplesTest.cs b/test/TensorFlowNET.UnitTest/ExamplesTests/ExamplesTest.cs index 9b889359..43613c4e 100644 --- a/test/TensorFlowNET.UnitTest/ExamplesTests/ExamplesTest.cs +++ b/test/TensorFlowNET.UnitTest/ExamplesTests/ExamplesTest.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; using Tensorflow; using TensorFlowNET.Examples; diff --git a/test/TensorFlowNET.UnitTest/GradientTest.cs b/test/TensorFlowNET.UnitTest/GradientTest.cs index f22ca2c7..3fb6b919 100644 --- a/test/TensorFlowNET.UnitTest/GradientTest.cs +++ b/test/TensorFlowNET.UnitTest/GradientTest.cs @@ -1,7 +1,4 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using System.Collections.Generic; -using System.Text; using Tensorflow; namespace TensorFlowNET.UnitTest diff --git a/test/TensorFlowNET.UnitTest/GraphTest.cs b/test/TensorFlowNET.UnitTest/GraphTest.cs index b83fd291..e50e19f8 100644 --- a/test/TensorFlowNET.UnitTest/GraphTest.cs +++ b/test/TensorFlowNET.UnitTest/GraphTest.cs @@ -1,8 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using System.Collections.Generic; -using System.Runtime.InteropServices; -using System.Text; using Tensorflow; using Buffer = Tensorflow.Buffer; using static Tensorflow.Python; diff --git a/test/TensorFlowNET.UnitTest/NameScopeTest.cs b/test/TensorFlowNET.UnitTest/NameScopeTest.cs index c25007c3..8d364c8b 100644 --- a/test/TensorFlowNET.UnitTest/NameScopeTest.cs +++ b/test/TensorFlowNET.UnitTest/NameScopeTest.cs @@ -1,7 +1,4 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using System.Collections.Generic; -using System.Text; using Tensorflow; using static Tensorflow.Python; diff --git a/test/TensorFlowNET.UnitTest/OperationsTest.cs b/test/TensorFlowNET.UnitTest/OperationsTest.cs index 91dda6fc..0359e4c3 100644 --- a/test/TensorFlowNET.UnitTest/OperationsTest.cs +++ b/test/TensorFlowNET.UnitTest/OperationsTest.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; using NumSharp; using Tensorflow; using Buffer = Tensorflow.Buffer; diff --git a/test/TensorFlowNET.UnitTest/PlaceholderTest.cs b/test/TensorFlowNET.UnitTest/PlaceholderTest.cs index 9f96f19b..c5a575c1 100644 --- a/test/TensorFlowNET.UnitTest/PlaceholderTest.cs +++ b/test/TensorFlowNET.UnitTest/PlaceholderTest.cs @@ -1,7 +1,4 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using System.Collections.Generic; -using System.Text; using Tensorflow; using static Tensorflow.Python; diff --git a/test/TensorFlowNET.UnitTest/PythonBaseTests.cs b/test/TensorFlowNET.UnitTest/PythonBaseTests.cs index c5010923..dff62549 100644 --- a/test/TensorFlowNET.UnitTest/PythonBaseTests.cs +++ b/test/TensorFlowNET.UnitTest/PythonBaseTests.cs @@ -1,7 +1,4 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using System.Collections.Generic; -using System.Text; using Tensorflow; using static Tensorflow.Python; diff --git a/test/TensorFlowNET.UnitTest/PythonTest.cs b/test/TensorFlowNET.UnitTest/PythonTest.cs index 7bf45840..d5d78425 100644 --- a/test/TensorFlowNET.UnitTest/PythonTest.cs +++ b/test/TensorFlowNET.UnitTest/PythonTest.cs @@ -1,8 +1,6 @@ using System; using System.Collections; -using System.Collections.Generic; using System.Linq; -using System.Text; using Microsoft.VisualStudio.TestTools.UnitTesting; using Newtonsoft.Json.Linq; using NumSharp; diff --git a/test/TensorFlowNET.UnitTest/SessionTest.cs b/test/TensorFlowNET.UnitTest/SessionTest.cs index c8aaa582..72e5e24a 100644 --- a/test/TensorFlowNET.UnitTest/SessionTest.cs +++ b/test/TensorFlowNET.UnitTest/SessionTest.cs @@ -2,7 +2,6 @@ using NumSharp; using System; using System.Collections.Generic; -using System.Text; using Tensorflow; using static Tensorflow.Python; diff --git a/test/TensorFlowNET.UnitTest/StatusTest.cs b/test/TensorFlowNET.UnitTest/StatusTest.cs index 7283e7a0..82728f50 100644 --- a/test/TensorFlowNET.UnitTest/StatusTest.cs +++ b/test/TensorFlowNET.UnitTest/StatusTest.cs @@ -1,7 +1,5 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using System; -using System.Collections.Generic; -using System.Text; using Tensorflow; namespace TensorFlowNET.UnitTest diff --git a/test/TensorFlowNET.UnitTest/TensorTest.cs b/test/TensorFlowNET.UnitTest/TensorTest.cs index 1713772e..9f4fff39 100644 --- a/test/TensorFlowNET.UnitTest/TensorTest.cs +++ b/test/TensorFlowNET.UnitTest/TensorTest.cs @@ -1,12 +1,9 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using NumSharp; using System; -using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; -using System.Text; using System.Threading; -using System.Threading.Tasks; using Tensorflow; using static Tensorflow.Python; diff --git a/test/TensorFlowNET.UnitTest/TrainSaverTest.cs b/test/TensorFlowNET.UnitTest/TrainSaverTest.cs index e02273b4..c437c862 100644 --- a/test/TensorFlowNET.UnitTest/TrainSaverTest.cs +++ b/test/TensorFlowNET.UnitTest/TrainSaverTest.cs @@ -1,8 +1,5 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using System; -using System.Collections.Generic; -using System.IO; -using System.Text; using Tensorflow; using static Tensorflow.Python; diff --git a/test/TensorFlowNET.UnitTest/VariableTest.cs b/test/TensorFlowNET.UnitTest/VariableTest.cs index d46ac903..a353bcc1 100644 --- a/test/TensorFlowNET.UnitTest/VariableTest.cs +++ b/test/TensorFlowNET.UnitTest/VariableTest.cs @@ -1,7 +1,4 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using System.Collections.Generic; -using System.Text; using Tensorflow; using static Tensorflow.Python; diff --git a/test/TensorFlowNET.UnitTest/VersionTest.cs b/test/TensorFlowNET.UnitTest/VersionTest.cs index 30900df0..f687efa6 100644 --- a/test/TensorFlowNET.UnitTest/VersionTest.cs +++ b/test/TensorFlowNET.UnitTest/VersionTest.cs @@ -1,7 +1,4 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using System.Collections.Generic; -using System.Text; using Tensorflow; namespace TensorFlowNET.UnitTest diff --git a/test/TensorFlowNET.UnitTest/c_test_util.cs b/test/TensorFlowNET.UnitTest/c_test_util.cs index edf3b379..c75bc616 100644 --- a/test/TensorFlowNET.UnitTest/c_test_util.cs +++ b/test/TensorFlowNET.UnitTest/c_test_util.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Runtime.InteropServices; -using System.Text; -using Tensorflow; +using Tensorflow; using Buffer = Tensorflow.Buffer; namespace TensorFlowNET.UnitTest diff --git a/test/TensorFlowNET.UnitTest/control_flow_ops_test/CondTestCases.cs b/test/TensorFlowNET.UnitTest/control_flow_ops_test/CondTestCases.cs index 675307fc..a116c91a 100644 --- a/test/TensorFlowNET.UnitTest/control_flow_ops_test/CondTestCases.cs +++ b/test/TensorFlowNET.UnitTest/control_flow_ops_test/CondTestCases.cs @@ -1,6 +1,4 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -using Newtonsoft.Json; -using System; using Tensorflow; using static Tensorflow.Python; diff --git a/test/TensorFlowNET.UnitTest/control_flow_ops_test/SwitchTestCase.cs b/test/TensorFlowNET.UnitTest/control_flow_ops_test/SwitchTestCase.cs index 1b81fc21..b4322ab3 100644 --- a/test/TensorFlowNET.UnitTest/control_flow_ops_test/SwitchTestCase.cs +++ b/test/TensorFlowNET.UnitTest/control_flow_ops_test/SwitchTestCase.cs @@ -1,5 +1,4 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; using Tensorflow; namespace TensorFlowNET.UnitTest.control_flow_ops_test diff --git a/test/TensorFlowNET.UnitTest/control_flow_ops_test/WhileContextTestCase.cs b/test/TensorFlowNET.UnitTest/control_flow_ops_test/WhileContextTestCase.cs index 77398f92..47cb397a 100644 --- a/test/TensorFlowNET.UnitTest/control_flow_ops_test/WhileContextTestCase.cs +++ b/test/TensorFlowNET.UnitTest/control_flow_ops_test/WhileContextTestCase.cs @@ -1,10 +1,6 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using Microsoft.VisualStudio.TestTools.UnitTesting; using Tensorflow; -using Tensorflow.Operations; using static Tensorflow.Python; namespace TensorFlowNET.UnitTest.control_flow_ops_test diff --git a/test/TensorFlowNET.UnitTest/gradients_test/GradientsTest.cs b/test/TensorFlowNET.UnitTest/gradients_test/GradientsTest.cs index 67a84d48..b9149c88 100644 --- a/test/TensorFlowNET.UnitTest/gradients_test/GradientsTest.cs +++ b/test/TensorFlowNET.UnitTest/gradients_test/GradientsTest.cs @@ -1,541 +1,541 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using NumSharp; -using Tensorflow; -using static Tensorflow.Python; - -namespace TensorFlowNET.UnitTest.gradients_test -{ - [TestClass] - public class GradientsTest : PythonTest - { - [Ignore("TODO")] - [TestMethod] - public void testGradients() - { - with(tf.Graph().as_default(), g => - { - var inp = tf.constant(1.0, shape: new[] { 32, 100 }, name: "in"); - var w = tf.constant(1.0, shape: new[] { 100, 10 }, name: "w"); - var b = tf.constant(1.0, shape: new[] { 10 }, name: "b"); - var xw = math_ops.matmul(inp, w, name: "xw"); - var h = nn_ops.bias_add(xw, b, name: "h"); - var w_grad = gradients_impl.gradients(new[] { h }, new[] { w })[0]; - self.assertEquals("MatMul", w_grad.op.type); - // TODO: Operation._original_op - //self.assertEquals(w_grad.op._original_op, xw.op); - self.assertTrue((bool)w_grad.op.get_attr("transpose_a")); - self.assertFalse((bool)w_grad.op.get_attr("transpose_b")); - }); - } - - [TestMethod] - public void testBatchMatMulGradient() - { - var a = tf.constant(np.array(Enumerable.Range(1, 18).Select(elem => (float)elem).ToArray()), shape:new []{2, 3, 3}); - var b = tf.divide(a, tf.constant(2.0f)); - var c = tf.batch_matmul(a, b); - var g = tf.gradients(c, new[] {a, b}, stop_gradients: new[] {a, b}); - var checkG = new[] - { - 3.0f, 7.5f, 12.0f, - 3.0f, 7.5f, 12.0f, - 3.0f, 7.5f, 12.0f, - 16.5f, 21.0f, 25.5f, - 16.5f, 21.0f, 25.5f, - 16.5f, 21.0f, 25.5f, - 12.0f, 12.0f, 12.0f, - 15.0f, 15.0f, 15.0f, - 18.0f, 18.0f, 18.0f, - 39.0f, 39.0f, 39.0f, - 42.0f, 42.0f, 42.0f, - 45.0f, 45.0f, 45.0f - }; - using (var sess = tf.Session()) - { - var result = sess.run(g); - var resultList = result[0].GetData().ToList(); - resultList.AddRange(result[1].GetData()); - Console.WriteLine(result.ToString()); - CollectionAssert.AreEqual(resultList.ToArray(), checkG); - } - } - - - [Ignore("TODO")] - [TestMethod] - public void testUnusedOutput() - { - //def testUnusedOutput(self): - // with ops.Graph().as_default(): - // w = constant(1.0, shape=[2, 2]) - // x = constant(1.0, shape=[2, 2]) - // wx = math_ops.matmul(w, x) - // split_wx = array_ops.split(value=wx, num_or_size_splits=2, axis=0) - // c = math_ops.reduce_sum(split_wx[1]) - // gw = gradients.gradients(c, [w])[0] - // self.assertEquals("MatMul", gw.op.type) - } - - [Ignore("TODO")] - [TestMethod] - public void testColocateGradients() - { - - //def testColocateGradients(self): - // with ops.Graph().as_default() as g: - // w = constant(1.0, shape=[1, 1]) - // x = constant(1.0, shape=[1, 2]) - // with g.device("/device:GPU:0"): - // wx = math_ops.matmul(w, x) - // gw = gradients.gradients(wx, [w], colocate_gradients_with_ops=True)[0] - // self.assertEqual(gw.op.colocation_groups(), wx.op.colocation_groups()) - } - - [Ignore("TODO")] - [TestMethod] - public void testColocateGradientsWithAggregation() - { - //def testColocateGradientsWithAggregation(self): - // with ops.Graph().as_default() as g: - // with g.device("/device:GPU:1"): - // w = constant(1.0, shape=[1, 1]) - // x = constant(1.0, shape=[1, 2]) - // y = constant(1.0, shape=[1, 2]) - // wx = math_ops.matmul(w, x) - // wy = math_ops.matmul(w, y) - // with g.device("/device:GPU:0"): - // z = wx + wy - - // gw1 = gradients.gradients(z, [w], colocate_gradients_with_ops=True)[0] - // self.assertEqual(gw1.op.colocation_groups(), wx.op.colocation_groups()) - - // gw2 = gradients.gradients(z, [w], colocate_gradients_with_ops=False)[0] - // self.assertTrue(wx.op.colocation_groups() != gw2.op.colocation_groups()) - - } - - [Ignore("TODO")] - [TestMethod] - public void testColocateGradientsWithAggregationInMultipleDevices() - { - //def testColocateGradientsWithAggregationInMultipleDevices(self): - // with ops.Graph().as_default() as g: - // with g.device("/device:GPU:1"): - // w = constant(1.0, shape=[1, 1]) - // x = constant(1.0, shape=[1, 2]) - // y = constant(1.0, shape=[1, 2]) - // with g.device("/task:1"): - // wx = math_ops.matmul(w, x) - // with g.device("/task:2"): - // wy = math_ops.matmul(w, y) - // with g.device("/device:GPU:0"): - // z = wx + wy - - // gw1 = gradients.gradients(z, [w], colocate_gradients_with_ops=True)[0] - // self.assertEqual(gw1.op.colocation_groups(), w.op.colocation_groups()) - - // gw2 = gradients.gradients(z, [w], colocate_gradients_with_ops=False)[0] - // self.assertTrue(w.op.colocation_groups() != gw2.op.colocation_groups()) - } - - - [Ignore("TODO")] - [TestMethod] - public void testColocateGradientsWithGateGradients() - { - - //def testColocateGradientsWithGateGradients(self): - // if not test_util.is_gpu_available(): - // self.skipTest("No GPU available") - // with ops.Graph().as_default() as g: - // with g.device("/device:CPU:0"): - // x = constant(1.0, shape=[1, 1]) - // y = constant(1.0, shape=[1, 1]) - // s = x + y - // with g.device("/device:GPU:0"): - // z = math_ops.reduce_sum(s) - - // gz_x = gradients.gradients(z, [x], colocate_gradients_with_ops=True, - // gate_gradients=True)[0] - // with session.Session(): - // # Make sure the placer doesn't complain. - // self.evaluate(gz_x) - - } - - [Ignore("TODO")] - [TestMethod] - public void testBoundaryStop() - { - //def testBoundaryStop(self): - // # Test that we don't differentiate 'x'. The gradient function for 'x' is - // # set explicitly to None so we will get an exception if the gradient code - // # tries to differentiate 'x'. - // with ops.Graph().as_default(): - // c = constant(1.0) - // x = array_ops.identity(c) - // y = x + 1.0 - // z = y + 1 - // grads = gradients.gradients(z, [x]) - // self.assertTrue(all(x is not None for x in grads)) - - } - - [Ignore("TODO")] - [TestMethod] - public void testBoundaryContinue() - { - //@test_util.run_v1_only("b/120545219") - //def testBoundaryContinue(self): - // # Test that we differentiate both 'x' and 'y' correctly when x is a - // # predecessor of y. - // with self.cached_session(): - // x = constant(1.0) - // y = x * 2.0 - // z = y * 3.0 - // grads = gradients.gradients(z, [x, y]) - // self.assertTrue(all(x is not None for x in grads)) - // self.assertEqual(6.0, grads[0].eval()) - - } - - [Ignore("TODO")] - [TestMethod] - public void testAggregationMethodAccumulateN() - { - - //@test_util.run_v1_only("b/120545219") - //def testAggregationMethodAccumulateN(self): - // with self.cached_session(): - // x = constant(1.0) - // y = x * 2.0 - // z = y + y + y + y + y + y + y + y + y + y - // grads = gradients.gradients( - // z, [x, y], - // aggregation_method=gradients.AggregationMethod. - // EXPERIMENTAL_ACCUMULATE_N) - // self.assertTrue(all(x is not None for x in grads)) - // self.assertEqual(20.0, grads[0].eval()) - // self.assertEqual(10.0, grads[1].eval()) - - } - - [Ignore("TODO")] - [TestMethod] - public void testAggregationMethodAddN() - { - //@test_util.run_v1_only("b/120545219") - //def testAggregationMethodAddN(self): - // with self.cached_session(): - // x = constant(1.0) - // y = x * 2.0 - // z = y + y + y + y + y + y + y + y + y + y - // grads = gradients.gradients( - // z, [x, y], aggregation_method=gradients.AggregationMethod.ADD_N) - // self.assertTrue(all(x is not None for x in grads)) - // self.assertEqual(20.0, grads[0].eval()) - // self.assertEqual(10.0, grads[1].eval()) - - - } - - [Ignore("TODO")] - [TestMethod] - public void testAggregationMethodTree() - { - //@test_util.run_v1_only("b/120545219") - //def testAggregationMethodTree(self): - // with self.cached_session(): - // x = constant(1.0) - // y = x * 2.0 - // z = y + y + y + y + y + y + y + y + y + y - // grads = gradients.gradients( - // z, [x, y], - // aggregation_method=gradients.AggregationMethod.EXPERIMENTAL_TREE) - // self.assertTrue(all(x is not None for x in grads)) - // self.assertEqual(20.0, grads[0].eval()) - // self.assertEqual(10.0, grads[1].eval()) - - } - - [Ignore("TODO")] - [TestMethod] - public void testNoGradientForStringOutputs() - { - - //def testNoGradientForStringOutputs(self): - // with ops.Graph().as_default(): - - // def _TestOpGrad(_, float_grad, string_grad): - // """Gradient function for TestStringOutput.""" - // self.assertEquals(float_grad.dtype, dtypes.float32) - // self.assertFalse(string_grad) - // return float_grad - - // ops.RegisterGradient("TestStringOutput")(_TestOpGrad) - - // c = constant(1.0) - // x, _ = test_ops.test_string_output(c) - // z = x * 2.0 - // w = z * 3.0 - // grads = gradients.gradients(z, [c]) - // self.assertTrue(isinstance(grads[0], ops.Tensor)) - // grads = gradients.gradients(w, [c]) - // self.assertTrue(isinstance(grads[0], ops.Tensor)) - } - - [Ignore("TODO")] - [TestMethod] - public void testSingletonIndexedSlices() - { - - //def testSingletonIndexedSlices(self): - // with ops.Graph().as_default(): - // x = array_ops.placeholder(dtypes.float32) - // y = array_ops.identity(x) - // dy = ops.IndexedSlices( - // array_ops.placeholder(dtypes.float32), - // array_ops.placeholder(dtypes.int32)) - // dx, = gradients.gradients(y, x, grad_ys=dy) - // # The IndexedSlices gradient of tf.identity is the identity map. - // with self.cached_session() as sess: - // vdx, vdy = sess.run( - // [dx, dy], feed_dict={x: [1.0], dy.indices: [0], dy.values: [2.0]}) - // self.assertEqual(vdx, vdy) - } - - [Ignore("TODO")] - [TestMethod] - public void testNonDifferentiableSwitchInWhileLoop() - { - - - //@test_util.run_v1_only("b/120545219") - //def testNonDifferentiableSwitchInWhileLoop(self): - // with ops.Graph().as_default(): - // v = array_ops.placeholder(dtypes.float32, []) - - // def _Step(i, a, ta): - // a += math_ops.cast(v, dtypes.int32) - // return (i + 1, a, ta.write(i, a)) - - // n = 4 - // i, _, ta = control_flow_ops.while_loop( - // lambda i, *_: i < n, - // _Step, [0, 0, tensor_array_ops.TensorArray( - // dtypes.int32, size=n)]) - // target = ta.read(i - 1) - // grad, = gradients.gradients(target, v) - // self.assertIsNone(grad) - - } - - [Ignore("TODO")] - [TestMethod] - public void testVariableReadValueGradient() - { - - //def testVariableReadValueGradient(self): - // with ops.Graph().as_default(): - // init = constant_op.constant(100.0) - // var = variables.Variable(init) - // gradient = gradients.gradients(var.read_value(), var) - // self.assertIsNotNone(gradient) - } - - [Ignore("TODO")] - [TestMethod] - public void testVariableAsGraphElementGradient() - { - //def testVariableAsGraphElementGradient(self): - // with ops.Graph().as_default() as graph: - // init = constant_op.constant(100.0) - // var = variables.Variable(init) - // gradient = gradients.gradients(graph.as_graph_element(var), var) - // self.assertIsNotNone(gradient) - } - - [Ignore("TODO")] - [TestMethod] - public void testVariableRefGradient() - { - - //@test_util.run_v1_only("b/120545219") - //def testVariableRefGradient(self): - // with ops.Graph().as_default(): - // init = constant_op.constant(100.0) - // var = variables.VariableV1(init) - // gradient = gradients.gradients(var._ref(), var) - // self.assertIsNotNone(gradient) - } - - [Ignore("TODO")] - [TestMethod] - public void testDependentYs() - { - //@test_util.run_v1_only("b/120545219") - //def testDependentYs(self): - // with self.cached_session(): - // x = constant_op.constant(3.0) - // y = math_ops.square(x) - // y1 = math_ops.square(y) - // y2 = math_ops.square(y1) - // g = gradients.gradients([y, y2], x) - // self.assertAllClose(17502.0, g[0].eval()) - // g = gradients.gradients(y + y2, x) - // self.assertAllClose(17502.0, g[0].eval()) - // z = array_ops.identity(y) - // z2 = array_ops.identity(y2) - // g = gradients.gradients([z, z2], x) - // self.assertAllClose(17502.0, g[0].eval()) - - } - - [Ignore("TODO")] - [TestMethod] - public void testPartialDerivatives() - { - - //@test_util.run_v1_only("b/120545219") - //def testPartialDerivatives(self): - // with self.cached_session(): - // x = constant_op.constant(1.) - // y = 2 * x - // z = x + y - // totalg = gradients.gradients(z, [x, y]) - // self.assertEqual([3.0, 1.0], [g.eval() for g in totalg]) - // partialg = gradients.gradients(z, [x, y], stop_gradients=[x, y]) - // self.assertEqual([1.0, 1.0], [g.eval() for g in partialg]) - } - - [Ignore("TODO")] - [TestMethod] - public void testStopGradients() - { - - - //@test_util.run_v1_only("b/120545219") - //def testStopGradients(self): - // def _MakeGraph(rng, stop_gradients=()): - // def _FunctionOf(xs, k=3): - // return ops.convert_to_tensor( - // sum(math_ops.matmul(rng.rand(k, k), x) for x in xs) - // + rng.rand(k, k)) - - // a = _FunctionOf([]) - // if "a" in stop_gradients: a = array_ops.stop_gradient(a) - // b = _FunctionOf([a]) - // if "b" in stop_gradients: b = array_ops.stop_gradient(b) - // c = _FunctionOf([a, b]) - // if "c" in stop_gradients: c = array_ops.stop_gradient(c) - // d = _FunctionOf([b, c]) - // if "d" in stop_gradients: d = array_ops.stop_gradient(d) - // return dict(a=a, b=b, c=c, d=d) - - // def _Gradients(ys, xs, **kwargs): - // dydxs = gradients.gradients(ys, xs, **kwargs) - // dydxs = [0. * x if dydx is None else dydx - // for x, dydx in zip(xs, dydxs)] - // return dydxs - // seed = np.random.randint(1000) - // cases = [] - // subsets = [""] + "a b c d ab ac ad bc bd cd abc abd acd bcd abcd".split() - // graph = _MakeGraph(np.random.RandomState(seed)) - // for constants in subsets: - // graph_with_stops = _MakeGraph(np.random.RandomState(seed), constants) - // for variables_ in subsets: - // # compute the gradient when stopped using tf.stop_gradients - // grad1 = _Gradients([graph_with_stops["d"]], - // [graph_with_stops[v] for v in variables_]) - // # compute the gradient when stopped using the stop_gradients kwarg - // grad2 = _Gradients([graph["d"]], - // [graph[v] for v in variables_], - // stop_gradients=[graph[v] for v in constants]) - // cases.append(dict(grad1=grad1, grad2=grad2, - // constants=constants, variables=variables_)) - - // # evaluate all tensors in one call to session.run for speed - // with self.cached_session() as sess: - // results = sess.run([(case["grad1"], case["grad2"]) for case in cases]) - - // for (npgrad1, npgrad2), case in zip(results, cases): - // for a, b in zip(npgrad1, npgrad2): - // np.testing.assert_allclose(a, b) - - } - - [Ignore("TODO")] - [TestMethod] - public void testUnconnectedGradientsNoneUnconnectedGradients() - { - - - //def testUnconnectedGradientsNoneUnconnectedGradients(self): - // with ops.Graph().as_default(): - // x = constant(1.0, shape=[2, 2]) - // y = constant(3.0, shape=[3, 1]) - // grad = gradients.gradients( - // [y], [x], unconnected_gradients="none") - // self.assertIsNone(grad[0]) - } - - [Ignore("TODO")] - [TestMethod] - public void testUnconnectedGradientsZerosUnconnectedGradients() - { - - - //def testUnconnectedGradientsZerosUnconnectedGradients(self): - // with ops.Graph().as_default(): - // x = constant(1.0, shape=[2, 2]) - // y = constant(3.0, shape=[3, 1]) - // grads = gradients.gradients( - // [y], [x], unconnected_gradients="zero") - // with self.cached_session() as sess: - // self.assertAllEqual([[0.0, 0.0], [0.0, 0.0]], self.evaluate(grads)[0]) - } - - [Ignore("TODO")] - [TestMethod] - public void testUnconnectedGradientsZeroConnectedGradients() - { - - - - //def testUnconnectedGradientsZeroConnectedGradients(self): - // with ops.Graph().as_default(): - // x = constant(1.0) - // y = x * 3.0 - // grad = gradients.gradients( - // [y], [x], unconnected_gradients="zero") - // with self.cached_session() as sess: - // self.assertEquals(3.0, self.evaluate(grad)[0]) - } - - [Ignore("TODO")] - [TestMethod] - public void testUnknownUnconnectedGradientsValueGiven() - { - //def testUnknownUnconnectedGradientsValueGiven(self): - // with ops.Graph().as_default(): - // x = constant(1.0) - // y = constant(1.0) - // with self.assertRaisesRegexp( - // ValueError, "Unknown value for unconnected_gradients: 'nonsense'"): - // gradients.gradients([y], [x], unconnected_gradients="nonsense") - - } - - - - /* - - - - */ - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using NumSharp; +using Tensorflow; +using static Tensorflow.Python; + +namespace TensorFlowNET.UnitTest.gradients_test +{ + [TestClass] + public class GradientsTest : PythonTest + { + [Ignore("TODO")] + [TestMethod] + public void testGradients() + { + with(tf.Graph().as_default(), g => + { + var inp = tf.constant(1.0, shape: new[] { 32, 100 }, name: "in"); + var w = tf.constant(1.0, shape: new[] { 100, 10 }, name: "w"); + var b = tf.constant(1.0, shape: new[] { 10 }, name: "b"); + var xw = math_ops.matmul(inp, w, name: "xw"); + var h = nn_ops.bias_add(xw, b, name: "h"); + var w_grad = gradients_impl.gradients(new[] { h }, new[] { w })[0]; + self.assertEquals("MatMul", w_grad.op.type); + // TODO: Operation._original_op + //self.assertEquals(w_grad.op._original_op, xw.op); + self.assertTrue((bool)w_grad.op.get_attr("transpose_a")); + self.assertFalse((bool)w_grad.op.get_attr("transpose_b")); + }); + } + + [TestMethod] + public void testBatchMatMulGradient() + { + var a = tf.constant(np.array(Enumerable.Range(1, 18).Select(elem => (float)elem).ToArray()), shape:new []{2, 3, 3}); + var b = tf.divide(a, tf.constant(2.0f)); + var c = tf.batch_matmul(a, b); + var g = tf.gradients(c, new[] {a, b}, stop_gradients: new[] {a, b}); + var checkG = new[] + { + 3.0f, 7.5f, 12.0f, + 3.0f, 7.5f, 12.0f, + 3.0f, 7.5f, 12.0f, + 16.5f, 21.0f, 25.5f, + 16.5f, 21.0f, 25.5f, + 16.5f, 21.0f, 25.5f, + 12.0f, 12.0f, 12.0f, + 15.0f, 15.0f, 15.0f, + 18.0f, 18.0f, 18.0f, + 39.0f, 39.0f, 39.0f, + 42.0f, 42.0f, 42.0f, + 45.0f, 45.0f, 45.0f + }; + using (var sess = tf.Session()) + { + var result = sess.run(g); + var resultList = result[0].GetData().ToList(); + resultList.AddRange(result[1].GetData()); + Console.WriteLine(result.ToString()); + CollectionAssert.AreEqual(resultList.ToArray(), checkG); + } + } + + + [Ignore("TODO")] + [TestMethod] + public void testUnusedOutput() + { + //def testUnusedOutput(self): + // with ops.Graph().as_default(): + // w = constant(1.0, shape=[2, 2]) + // x = constant(1.0, shape=[2, 2]) + // wx = math_ops.matmul(w, x) + // split_wx = array_ops.split(value=wx, num_or_size_splits=2, axis=0) + // c = math_ops.reduce_sum(split_wx[1]) + // gw = gradients.gradients(c, [w])[0] + // self.assertEquals("MatMul", gw.op.type) + } + + [Ignore("TODO")] + [TestMethod] + public void testColocateGradients() + { + + //def testColocateGradients(self): + // with ops.Graph().as_default() as g: + // w = constant(1.0, shape=[1, 1]) + // x = constant(1.0, shape=[1, 2]) + // with g.device("/device:GPU:0"): + // wx = math_ops.matmul(w, x) + // gw = gradients.gradients(wx, [w], colocate_gradients_with_ops=True)[0] + // self.assertEqual(gw.op.colocation_groups(), wx.op.colocation_groups()) + } + + [Ignore("TODO")] + [TestMethod] + public void testColocateGradientsWithAggregation() + { + //def testColocateGradientsWithAggregation(self): + // with ops.Graph().as_default() as g: + // with g.device("/device:GPU:1"): + // w = constant(1.0, shape=[1, 1]) + // x = constant(1.0, shape=[1, 2]) + // y = constant(1.0, shape=[1, 2]) + // wx = math_ops.matmul(w, x) + // wy = math_ops.matmul(w, y) + // with g.device("/device:GPU:0"): + // z = wx + wy + + // gw1 = gradients.gradients(z, [w], colocate_gradients_with_ops=True)[0] + // self.assertEqual(gw1.op.colocation_groups(), wx.op.colocation_groups()) + + // gw2 = gradients.gradients(z, [w], colocate_gradients_with_ops=False)[0] + // self.assertTrue(wx.op.colocation_groups() != gw2.op.colocation_groups()) + + } + + [Ignore("TODO")] + [TestMethod] + public void testColocateGradientsWithAggregationInMultipleDevices() + { + //def testColocateGradientsWithAggregationInMultipleDevices(self): + // with ops.Graph().as_default() as g: + // with g.device("/device:GPU:1"): + // w = constant(1.0, shape=[1, 1]) + // x = constant(1.0, shape=[1, 2]) + // y = constant(1.0, shape=[1, 2]) + // with g.device("/task:1"): + // wx = math_ops.matmul(w, x) + // with g.device("/task:2"): + // wy = math_ops.matmul(w, y) + // with g.device("/device:GPU:0"): + // z = wx + wy + + // gw1 = gradients.gradients(z, [w], colocate_gradients_with_ops=True)[0] + // self.assertEqual(gw1.op.colocation_groups(), w.op.colocation_groups()) + + // gw2 = gradients.gradients(z, [w], colocate_gradients_with_ops=False)[0] + // self.assertTrue(w.op.colocation_groups() != gw2.op.colocation_groups()) + } + + + [Ignore("TODO")] + [TestMethod] + public void testColocateGradientsWithGateGradients() + { + + //def testColocateGradientsWithGateGradients(self): + // if not test_util.is_gpu_available(): + // self.skipTest("No GPU available") + // with ops.Graph().as_default() as g: + // with g.device("/device:CPU:0"): + // x = constant(1.0, shape=[1, 1]) + // y = constant(1.0, shape=[1, 1]) + // s = x + y + // with g.device("/device:GPU:0"): + // z = math_ops.reduce_sum(s) + + // gz_x = gradients.gradients(z, [x], colocate_gradients_with_ops=True, + // gate_gradients=True)[0] + // with session.Session(): + // # Make sure the placer doesn't complain. + // self.evaluate(gz_x) + + } + + [Ignore("TODO")] + [TestMethod] + public void testBoundaryStop() + { + //def testBoundaryStop(self): + // # Test that we don't differentiate 'x'. The gradient function for 'x' is + // # set explicitly to None so we will get an exception if the gradient code + // # tries to differentiate 'x'. + // with ops.Graph().as_default(): + // c = constant(1.0) + // x = array_ops.identity(c) + // y = x + 1.0 + // z = y + 1 + // grads = gradients.gradients(z, [x]) + // self.assertTrue(all(x is not None for x in grads)) + + } + + [Ignore("TODO")] + [TestMethod] + public void testBoundaryContinue() + { + //@test_util.run_v1_only("b/120545219") + //def testBoundaryContinue(self): + // # Test that we differentiate both 'x' and 'y' correctly when x is a + // # predecessor of y. + // with self.cached_session(): + // x = constant(1.0) + // y = x * 2.0 + // z = y * 3.0 + // grads = gradients.gradients(z, [x, y]) + // self.assertTrue(all(x is not None for x in grads)) + // self.assertEqual(6.0, grads[0].eval()) + + } + + [Ignore("TODO")] + [TestMethod] + public void testAggregationMethodAccumulateN() + { + + //@test_util.run_v1_only("b/120545219") + //def testAggregationMethodAccumulateN(self): + // with self.cached_session(): + // x = constant(1.0) + // y = x * 2.0 + // z = y + y + y + y + y + y + y + y + y + y + // grads = gradients.gradients( + // z, [x, y], + // aggregation_method=gradients.AggregationMethod. + // EXPERIMENTAL_ACCUMULATE_N) + // self.assertTrue(all(x is not None for x in grads)) + // self.assertEqual(20.0, grads[0].eval()) + // self.assertEqual(10.0, grads[1].eval()) + + } + + [Ignore("TODO")] + [TestMethod] + public void testAggregationMethodAddN() + { + //@test_util.run_v1_only("b/120545219") + //def testAggregationMethodAddN(self): + // with self.cached_session(): + // x = constant(1.0) + // y = x * 2.0 + // z = y + y + y + y + y + y + y + y + y + y + // grads = gradients.gradients( + // z, [x, y], aggregation_method=gradients.AggregationMethod.ADD_N) + // self.assertTrue(all(x is not None for x in grads)) + // self.assertEqual(20.0, grads[0].eval()) + // self.assertEqual(10.0, grads[1].eval()) + + + } + + [Ignore("TODO")] + [TestMethod] + public void testAggregationMethodTree() + { + //@test_util.run_v1_only("b/120545219") + //def testAggregationMethodTree(self): + // with self.cached_session(): + // x = constant(1.0) + // y = x * 2.0 + // z = y + y + y + y + y + y + y + y + y + y + // grads = gradients.gradients( + // z, [x, y], + // aggregation_method=gradients.AggregationMethod.EXPERIMENTAL_TREE) + // self.assertTrue(all(x is not None for x in grads)) + // self.assertEqual(20.0, grads[0].eval()) + // self.assertEqual(10.0, grads[1].eval()) + + } + + [Ignore("TODO")] + [TestMethod] + public void testNoGradientForStringOutputs() + { + + //def testNoGradientForStringOutputs(self): + // with ops.Graph().as_default(): + + // def _TestOpGrad(_, float_grad, string_grad): + // """Gradient function for TestStringOutput.""" + // self.assertEquals(float_grad.dtype, dtypes.float32) + // self.assertFalse(string_grad) + // return float_grad + + // ops.RegisterGradient("TestStringOutput")(_TestOpGrad) + + // c = constant(1.0) + // x, _ = test_ops.test_string_output(c) + // z = x * 2.0 + // w = z * 3.0 + // grads = gradients.gradients(z, [c]) + // self.assertTrue(isinstance(grads[0], ops.Tensor)) + // grads = gradients.gradients(w, [c]) + // self.assertTrue(isinstance(grads[0], ops.Tensor)) + } + + [Ignore("TODO")] + [TestMethod] + public void testSingletonIndexedSlices() + { + + //def testSingletonIndexedSlices(self): + // with ops.Graph().as_default(): + // x = array_ops.placeholder(dtypes.float32) + // y = array_ops.identity(x) + // dy = ops.IndexedSlices( + // array_ops.placeholder(dtypes.float32), + // array_ops.placeholder(dtypes.int32)) + // dx, = gradients.gradients(y, x, grad_ys=dy) + // # The IndexedSlices gradient of tf.identity is the identity map. + // with self.cached_session() as sess: + // vdx, vdy = sess.run( + // [dx, dy], feed_dict={x: [1.0], dy.indices: [0], dy.values: [2.0]}) + // self.assertEqual(vdx, vdy) + } + + [Ignore("TODO")] + [TestMethod] + public void testNonDifferentiableSwitchInWhileLoop() + { + + + //@test_util.run_v1_only("b/120545219") + //def testNonDifferentiableSwitchInWhileLoop(self): + // with ops.Graph().as_default(): + // v = array_ops.placeholder(dtypes.float32, []) + + // def _Step(i, a, ta): + // a += math_ops.cast(v, dtypes.int32) + // return (i + 1, a, ta.write(i, a)) + + // n = 4 + // i, _, ta = control_flow_ops.while_loop( + // lambda i, *_: i < n, + // _Step, [0, 0, tensor_array_ops.TensorArray( + // dtypes.int32, size=n)]) + // target = ta.read(i - 1) + // grad, = gradients.gradients(target, v) + // self.assertIsNone(grad) + + } + + [Ignore("TODO")] + [TestMethod] + public void testVariableReadValueGradient() + { + + //def testVariableReadValueGradient(self): + // with ops.Graph().as_default(): + // init = constant_op.constant(100.0) + // var = variables.Variable(init) + // gradient = gradients.gradients(var.read_value(), var) + // self.assertIsNotNone(gradient) + } + + [Ignore("TODO")] + [TestMethod] + public void testVariableAsGraphElementGradient() + { + //def testVariableAsGraphElementGradient(self): + // with ops.Graph().as_default() as graph: + // init = constant_op.constant(100.0) + // var = variables.Variable(init) + // gradient = gradients.gradients(graph.as_graph_element(var), var) + // self.assertIsNotNone(gradient) + } + + [Ignore("TODO")] + [TestMethod] + public void testVariableRefGradient() + { + + //@test_util.run_v1_only("b/120545219") + //def testVariableRefGradient(self): + // with ops.Graph().as_default(): + // init = constant_op.constant(100.0) + // var = variables.VariableV1(init) + // gradient = gradients.gradients(var._ref(), var) + // self.assertIsNotNone(gradient) + } + + [Ignore("TODO")] + [TestMethod] + public void testDependentYs() + { + //@test_util.run_v1_only("b/120545219") + //def testDependentYs(self): + // with self.cached_session(): + // x = constant_op.constant(3.0) + // y = math_ops.square(x) + // y1 = math_ops.square(y) + // y2 = math_ops.square(y1) + // g = gradients.gradients([y, y2], x) + // self.assertAllClose(17502.0, g[0].eval()) + // g = gradients.gradients(y + y2, x) + // self.assertAllClose(17502.0, g[0].eval()) + // z = array_ops.identity(y) + // z2 = array_ops.identity(y2) + // g = gradients.gradients([z, z2], x) + // self.assertAllClose(17502.0, g[0].eval()) + + } + + [Ignore("TODO")] + [TestMethod] + public void testPartialDerivatives() + { + + //@test_util.run_v1_only("b/120545219") + //def testPartialDerivatives(self): + // with self.cached_session(): + // x = constant_op.constant(1.) + // y = 2 * x + // z = x + y + // totalg = gradients.gradients(z, [x, y]) + // self.assertEqual([3.0, 1.0], [g.eval() for g in totalg]) + // partialg = gradients.gradients(z, [x, y], stop_gradients=[x, y]) + // self.assertEqual([1.0, 1.0], [g.eval() for g in partialg]) + } + + [Ignore("TODO")] + [TestMethod] + public void testStopGradients() + { + + + //@test_util.run_v1_only("b/120545219") + //def testStopGradients(self): + // def _MakeGraph(rng, stop_gradients=()): + // def _FunctionOf(xs, k=3): + // return ops.convert_to_tensor( + // sum(math_ops.matmul(rng.rand(k, k), x) for x in xs) + // + rng.rand(k, k)) + + // a = _FunctionOf([]) + // if "a" in stop_gradients: a = array_ops.stop_gradient(a) + // b = _FunctionOf([a]) + // if "b" in stop_gradients: b = array_ops.stop_gradient(b) + // c = _FunctionOf([a, b]) + // if "c" in stop_gradients: c = array_ops.stop_gradient(c) + // d = _FunctionOf([b, c]) + // if "d" in stop_gradients: d = array_ops.stop_gradient(d) + // return dict(a=a, b=b, c=c, d=d) + + // def _Gradients(ys, xs, **kwargs): + // dydxs = gradients.gradients(ys, xs, **kwargs) + // dydxs = [0. * x if dydx is None else dydx + // for x, dydx in zip(xs, dydxs)] + // return dydxs + // seed = np.random.randint(1000) + // cases = [] + // subsets = [""] + "a b c d ab ac ad bc bd cd abc abd acd bcd abcd".split() + // graph = _MakeGraph(np.random.RandomState(seed)) + // for constants in subsets: + // graph_with_stops = _MakeGraph(np.random.RandomState(seed), constants) + // for variables_ in subsets: + // # compute the gradient when stopped using tf.stop_gradients + // grad1 = _Gradients([graph_with_stops["d"]], + // [graph_with_stops[v] for v in variables_]) + // # compute the gradient when stopped using the stop_gradients kwarg + // grad2 = _Gradients([graph["d"]], + // [graph[v] for v in variables_], + // stop_gradients=[graph[v] for v in constants]) + // cases.append(dict(grad1=grad1, grad2=grad2, + // constants=constants, variables=variables_)) + + // # evaluate all tensors in one call to session.run for speed + // with self.cached_session() as sess: + // results = sess.run([(case["grad1"], case["grad2"]) for case in cases]) + + // for (npgrad1, npgrad2), case in zip(results, cases): + // for a, b in zip(npgrad1, npgrad2): + // np.testing.assert_allclose(a, b) + + } + + [Ignore("TODO")] + [TestMethod] + public void testUnconnectedGradientsNoneUnconnectedGradients() + { + + + //def testUnconnectedGradientsNoneUnconnectedGradients(self): + // with ops.Graph().as_default(): + // x = constant(1.0, shape=[2, 2]) + // y = constant(3.0, shape=[3, 1]) + // grad = gradients.gradients( + // [y], [x], unconnected_gradients="none") + // self.assertIsNone(grad[0]) + } + + [Ignore("TODO")] + [TestMethod] + public void testUnconnectedGradientsZerosUnconnectedGradients() + { + + + //def testUnconnectedGradientsZerosUnconnectedGradients(self): + // with ops.Graph().as_default(): + // x = constant(1.0, shape=[2, 2]) + // y = constant(3.0, shape=[3, 1]) + // grads = gradients.gradients( + // [y], [x], unconnected_gradients="zero") + // with self.cached_session() as sess: + // self.assertAllEqual([[0.0, 0.0], [0.0, 0.0]], self.evaluate(grads)[0]) + } + + [Ignore("TODO")] + [TestMethod] + public void testUnconnectedGradientsZeroConnectedGradients() + { + + + + //def testUnconnectedGradientsZeroConnectedGradients(self): + // with ops.Graph().as_default(): + // x = constant(1.0) + // y = x * 3.0 + // grad = gradients.gradients( + // [y], [x], unconnected_gradients="zero") + // with self.cached_session() as sess: + // self.assertEquals(3.0, self.evaluate(grad)[0]) + } + + [Ignore("TODO")] + [TestMethod] + public void testUnknownUnconnectedGradientsValueGiven() + { + //def testUnknownUnconnectedGradientsValueGiven(self): + // with ops.Graph().as_default(): + // x = constant(1.0) + // y = constant(1.0) + // with self.assertRaisesRegexp( + // ValueError, "Unknown value for unconnected_gradients: 'nonsense'"): + // gradients.gradients([y], [x], unconnected_gradients="nonsense") + + } + + + + /* + + + + */ + } +} diff --git a/test/TensorFlowNET.UnitTest/nn_test/ZeroFractionTest.cs b/test/TensorFlowNET.UnitTest/nn_test/ZeroFractionTest.cs index 25f8409d..33a16ba8 100644 --- a/test/TensorFlowNET.UnitTest/nn_test/ZeroFractionTest.cs +++ b/test/TensorFlowNET.UnitTest/nn_test/ZeroFractionTest.cs @@ -1,7 +1,5 @@ using System; -using System.Collections.Generic; using System.Linq; -using System.Text; using Microsoft.VisualStudio.TestTools.UnitTesting; using NumSharp; using Tensorflow; diff --git a/test/TensorFlowNET.UnitTest/ops_test/ControlDependenciesTest.cs b/test/TensorFlowNET.UnitTest/ops_test/ControlDependenciesTest.cs index 3a806516..16618b4b 100644 --- a/test/TensorFlowNET.UnitTest/ops_test/ControlDependenciesTest.cs +++ b/test/TensorFlowNET.UnitTest/ops_test/ControlDependenciesTest.cs @@ -1,7 +1,5 @@ using System; -using System.Collections.Generic; using System.Linq; -using System.Text; using Microsoft.VisualStudio.TestTools.UnitTesting; using Tensorflow; using Tensorflow.Eager; diff --git a/test/TensorFlowNET.UnitTest/ops_test/CreateOpFromTfOperationTest.cs b/test/TensorFlowNET.UnitTest/ops_test/CreateOpFromTfOperationTest.cs index 49ef4b56..a961d7ec 100644 --- a/test/TensorFlowNET.UnitTest/ops_test/CreateOpFromTfOperationTest.cs +++ b/test/TensorFlowNET.UnitTest/ops_test/CreateOpFromTfOperationTest.cs @@ -1,7 +1,5 @@ using System; -using System.Collections.Generic; using System.Linq; -using System.Text; using Microsoft.VisualStudio.TestTools.UnitTesting; using Tensorflow; using Tensorflow.Operations; diff --git a/test/TensorFlowNET.UnitTest/ops_test/GraphTest.cs b/test/TensorFlowNET.UnitTest/ops_test/GraphTest.cs index a4a8c299..87a34b8a 100644 --- a/test/TensorFlowNET.UnitTest/ops_test/GraphTest.cs +++ b/test/TensorFlowNET.UnitTest/ops_test/GraphTest.cs @@ -1,10 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; using Tensorflow; -using Tensorflow.Operations; namespace TensorFlowNET.UnitTest.ops_test {