scisharp / scisharp-stack-examples Goto Github PK
View Code? Open in Web Editor NEWPractical examples written in SciSharp's machine learning libraries
Home Page: http://scisharpstack.org
License: Apache License 2.0
Practical examples written in SciSharp's machine learning libraries
Home Page: http://scisharpstack.org
License: Apache License 2.0
There seems to be something wrong with the nuget packages.
I upgraded to
SciSharp.Tensorflow.Redist-Windows-GPU 2.10.0
TensorFlow.Keras 0.10.0
TensorFlow.NET 0.100.0
and use the code from the example MnistGAN.cs
in https://github.com/SciSharp/SciSharp-Stack-Examples/tree/master/src/TensorFlowNET.Examples/GAN
Code compiles, but:
There is only a few changes to the code in MnistGAN.cs to allow it to compile:
What is strange is that the code works just fine if code is compiled using all the source from SciSharp repositories, but when using the NuGet packages, it fails to improve.
Let me know if I made an error. My code is available here:
https://github.com/Darlanio/TensorFlowNetUpdatedGAN
In the readme file, https://github.com/SciSharp/SciSharp-Stack-Examples/blob/master/src/TensorFlowNET.Examples/ImageProcessing/ObjectDetection.cs throws a 404.
Hi folks,
I am using word2vec and I have added textfile instead of URL Web Download (text8.zip). The rest of the code is the same as the example written in word2vec.
...............
...............
// code omitted
...............
...............
int wordId = 0;
//text_words = File.ReadAllText($"word2vec{Path.DirectorySeparatorChar}text8").Trim().ToLower().Split();
string textFile = @"c:\...........\MyData.txt";
text_words = File.ReadAllText(textFile).Trim().ToLower().Split();
...............
...............
// code omitted
...............
...............
Here is my sample data text file (MyData.txt) as below:
This is Singapore and one two three four five and Test123 Kings are brave and Queens are beautiful Singapore is a really expensive country but really beautiful country and modern city
This is Malaysia and one two three four five and Test123 Kings are brave and Queens are beautiful Malaysia is a very old country but really beautiful country and old fashion city
This is Singapore and one two three four five and Test123 Kings are brave and Queens are beautiful Singapore is a really expensive country but really beautiful country and modern city
This is Malaysia and one two three four five and Test123 Kings are brave and Queens are beautiful Malaysia is a very old country but really beautiful country and old fashion city
The reading path file is working but I am getting an error message and it says:
graph\word2vec.meta already exists.
Words count: 129
Unique words: 27
Vocabulary size: 2
Most common words: UNK 0 113, and 1 16
2021-05-04 10:32:28.137672: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
Step 1, Average Loss= 610.5444
Evaluation...
System.InvalidOperationException: Sequence contains no matching element
at System.Linq.ThrowHelper.ThrowNoMatchException()
at System.Linq.Enumerable.First[TSource](IEnumerable`1 source, Func`2 predicate)
at TensorFlowNET.Examples.Word2Vec.Run() in C:\********************\SciSharp-Stack-Examples\src\TensorFlowNET.Examples\TextProcessing\Word2Vec.cs:line 114
at TensorFlowNET.Examples.Program.RunExamples(String key, IExample[] examples) in C:\Users\Adnan Salahuddin\Desktop\TensorFlow\SciSharp-Stack-Examples\src\TensorFlowNET.Examples\Program.cs:line 89
5/4/2021 5:32:29 AM Completed Word2Vec
Example: Word2Vec is Failed!
TensorFlow Binary v2.4.1
TensorFlow.NET v0.40.1.0
TensorFlow.Keras v0.5.1.0
I tried many times to fix this issue but still no clue. Could you please help me to solve this issue?
Thanking in anticipation
When running LogisticRegression
Example, I got an Exception:
System.InvalidOperationException: Can't construct NDCoordinatesIncrementor with an empty shape.
at NumSharp.Utilities.NDCoordinatesIncrementor..ctor(Shape& shape)
at NumSharp.NDArray._extract_indices(NDArray[] mindices, Boolean isCollapsed, NDArray out)
at Tensorflow.Hub.MnistDataSet.GetNextBatch(Int32 batch_size, Boolean fake_data, Boolean shuffle)
at TensorFlowNET.Examples.LogisticRegression.Run() in TensorFlow.NET-Examples/src/TensorFlowNET.Examples/BasicModels/LogisticRegression.cs:line 92
at TensorFlowNET.Examples.Program.Main(String[] args) in TensorFlow.NET-Examples/src/TensorFlowNET.Examples/Program.cs:line 75
A fix to this example could be modifying this line to the following:
var start = i * batch_size;
var end = (i + 1) * batch_size;
var (batch_xs, batch_ys) = mnist.GetNextBatch(mnist.Train.Data, mnist.Train.Labels, start, end);
I want to run YOLOV3, but there are some errors。。。
System.ArgumentNullException: Value cannot be null. (Parameter 'first')
at System.Linq.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
at System.Linq.Enumerable.Concat[TSource](IEnumerable1 first, IEnumerable
1 second)
at Tensorflow.Optimizer.compute_gradients(Tensor loss, List1 var_list, Nullable
1 aggregation_method, GateGradientType gate_gradients, Boolean colocate_gradients_with_ops, Tensor grad_loss)
at Tensorflow.Optimizer.minimize(Tensor loss, IVariableV1 global_step, List1 var_list, GateGradientType gate_gradients, Nullable
1 aggregation_method, Boolean colocate_gradients_with_ops, String name, Tensor grad_loss)
at TensorFlowNET.Examples.DigitRecognitionRNN.BuildGraph() in D:\workspace\CS\SciSharp-Stack-Examples-master\src\TensorFlowNET.Examples\ImageProcessing\DigitRecognitionRNN.cs:line 100
at TensorFlowNET.Examples.DigitRecognitionRNN.Run() in D:\workspace\CS\SciSharp-Stack-Examples-master\src\TensorFlowNET.Examples\ImageProcessing\DigitRecognitionRNN.cs:line 75
at TensorFlowNET.Examples.Program.RunExamples(String key, IExample[] examples) in D:\workspace\CS\SciSharp-Stack-Examples-master\src\TensorFlowNET.Examples\Program.cs:line 91
2020-10-28 05:29:20 Completed MNIST RNN (Graph)
Hello this is great for the C# community, can you please share some information /samples, i.e. do you have any samples for health drugs
or prescriptons
training models on doctors notes etc.
I saw there were some standars for each NER, but its hard to navigate your stack to figure out where this sits/belongs or even if there is a sample, we would appreciate the guidance or a sample
Often the use ase is that a doc's note could be a prescription or case history as a PDF or image. Using other engines we can get the text, but the NER is the challenge.
Hi, I'm currently trying to run a 'ImageRecognitionInception' example with my pre-trained model (which is .pb file)
and here comes a problem :
Tensorflow.InvalidArgumentError: 'Can not squeeze dim[1], expected a dimension of 1, got 3
[[{{node InceptionV1/Logits/SpatialSqueeze}}]]'
and here is the code
using NumSharp;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using Tensorflow;
using Tensorflow.Keras.Utils;
using static Tensorflow.Binding;
using Console = Colorful.Console;
namespace TensorFlowNET.Examples
{
/// Inception v3 is a widely-used image recognition model
/// that has been shown to attain greater than 78.1% accuracy on the ImageNet dataset.
/// The model is the culmination of many ideas developed by multiple researchers over the years.
public class ImageRecognitionInception : SciSharpExample, IExample
{
string dir = "ImageRecognitionInception";
string pbFile = "tensorflow_inception_graph.pb";
string labelFile = "imagenet_comp_graph_label_strings.txt";
List<NDArray> file_ndarrays = new List<NDArray>();
public ExampleConfig InitConfig()
=> Config = new ExampleConfig
{
Name = "Image Recognition Inception",
Enabled = true,
IsImportingGraph = false
};
public bool Run()
{
tf.compat.v1.disable_eager_execution();
PrepareData();
var graph = new Graph();
//import GraphDef from pb file
graph.Import(Path.Join(dir, pbFile));
var input_name = "input";
var output_name = "InceptionV1/Logits/Predictions/Softmax";
var input_operation = graph.OperationByName(input_name);
var output_operation = graph.OperationByName(output_name);
var labels = File.ReadAllLines(Path.Join(dir, labelFile));
var result_labels = new List<string>();
var sw = new Stopwatch();
using (var sess = tf.Session(graph))
{
foreach (var nd in file_ndarrays)
{
sw.Restart();
var results = sess.run(output_operation.outputs[0], (input_operation.outputs[0], nd)); // the error happens here
results = np.squeeze(results);
int idx = np.argmax(results);
Console.WriteLine($"{labels[idx]} {results[idx]} in {sw.ElapsedMilliseconds}ms", Color.Tan);
result_labels.Add(labels[idx]);
}
}
return result_labels.Contains("Blues");
}
private NDArray ReadTensorFromImageFile(string file_name,
int input_height = 288,
int input_width = 432,
int input_mean = 0,
int input_std = 255)
{
var graph = tf.Graph().as_default();
var file_reader = tf.io.read_file(file_name, "file_reader");
var decodeJpeg = tf.image.decode_jpeg(file_reader, channels: 3, name: "DecodeJpeg");
var cast = tf.cast(decodeJpeg, tf.float32);
var dims_expander = tf.expand_dims(cast, 0);
var resize = tf.constant(new int[] { input_height, input_width });
var bilinear = tf.image.resize_bilinear(dims_expander, resize);
var sub = tf.subtract(bilinear, new float[] { input_mean });
var normalized = tf.divide(sub, new float[] { input_std });
using (var sess = tf.Session(graph))
return sess.run(normalized);
}
public override void PrepareData()
{
//DirectoryInfo di = new DirectoryInfo(dir);
//di.Delete(true);
Directory.CreateDirectory(dir);
// get model file
string url = "https://github.com/dorodorodororo/trainedmodel/raw/main/trainedmodel.zip"; //my own trained model
Web.Download(url, dir, "trainedmodel.zip");
Compress.UnZip(Path.Join(dir, "trainedmodel.zip"), dir);
// download sample picture
Directory.CreateDirectory(Path.Join(dir, "img"));
url = $"https://raw.githubusercontent.com/dorodorodororo/Csharp/main/blues00081.jpg";
Web.Download(url, Path.Join(dir, "img"), "blues00081.jpg");
// load image file
var files = Directory.GetFiles(Path.Join(dir, "img"));
for (int i = 0; i < files.Length; i++)
{
var nd = ReadTensorFromImageFile(files[i]);
file_ndarrays.Add(nd);
}
}
}
}
It says it expected a dimension of 1, but mine is 3.
So I brought it on Netron and got this flowchart. (It's too large so I just got the output node.)
I don't know how to fix this problem.
Can fix this problem by using a V3 model in training instead of V1? (I made this .pb file using V1 model and I think you used model using V3)
I'd appreciate it if you could give me any suggestions or comments.
Thank you
Have a nice day!
Hello:
I want to know if I can use the repo to convert some pre-trained models to the models which can be used by the repo? For example, Nvidia StyleGAN3, they have a number of pre-trained model in .PKL format.
Can I use their pre-trained model (.pkl format) in the repo to make image prediction?
https://github.com/NVlabs/stylegan3
If yes, please give some general instructions on how to start.
By the way, I am using Visual Studio 2022 in Windows 10 (version 21H2).
Thanks,
Just downloaded the full Example project and ran the command:
dotnet run --project src/TensorFlowNET.Examples -ex "Linear Regression".
I got the following errors:
C:\Users\User\Documents\Projects\Internal\Vision\SciSharp-Stack-Examples-master>dotnet run --project src/TensorFlowNET.Examples -ex "Linear Regression"
ImageProcessing\DigitRecognitionRnnKeras.cs(130,41): error CS0246: The type or namespace name 'Tensors' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\User\Documents\Projects\Internal\Vision\SciSharp-Stack-Examples-master\src\TensorFlowNET.Examples\TensorFlowNET.Examples.csproj]
ImageProcessing\DigitRecognitionRnnKeras.cs(130,28): error CS0246: The type or namespace name 'Tensors' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\User\Documents\Projects\Internal\Vision\SciSharp-Stack-Examples-master\src\TensorFlowNET.Examples\TensorFlowNET.Examples.csproj]
NeuralNetworks\FullyConnectedKeras.cs(178,45): error CS0246: The type or namespace name 'Tensors' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\User\Documents\Projects\Internal\Vision\SciSharp-Stack-Examples-master\src\TensorFlowNET.Examples\TensorFlowNET.Examples.csproj]
NeuralNetworks\FullyConnectedKeras.cs(178,32): error CS0246: The type or namespace name 'Tensors' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\User\Documents\Projects\Internal\Vision\SciSharp-Stack-Examples-master\src\TensorFlowNET.Examples\TensorFlowNET.Examples.csproj]
ImageProcessing\DigitRecognitionCnnKeras.cs(207,45): error CS0246: The type or namespace name 'Tensors' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\User\Documents\Projects\Internal\Vision\SciSharp-Stack-Examples-master\src\TensorFlowNET.Examples\TensorFlowNET.Examples.csproj]
ImageProcessing\DigitRecognitionCnnKeras.cs(207,32): error CS0246: The type or namespace name 'Tensors' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\User\Documents\Projects\Internal\Vision\SciSharp-Stack-Examples-master\src\TensorFlowNET.Examples\TensorFlowNET.Examples.csproj]
ImageProcessing\TransferLearningWithInceptionV3.cs(512,21): warning CS0114: 'TransferLearningWithInceptionV3.PrepareData()' hides inherited member 'SciSharpExample.PrepareData()'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword. [C:\Users\User\Documents\Projects\Internal\Vision\SciSharp-Stack-Examples-master\src\TensorFlowNET.Examples\TensorFlowNET.Examples.csproj]
ImageProcessing\TransferLearningWithInceptionV3.cs(591,22): warning CS0114: 'TransferLearningWithInceptionV3.ImportGraph()' hides inherited member 'SciSharpExample.ImportGraph()'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword. [C:\Users\User\Documents\Projects\Internal\Vision\SciSharp-Stack-Examples-master\src\TensorFlowNET.Examples\TensorFlowNET.Examples.csproj]
TextProcessing\CnnTextClassification.cs(188,22): warning CS0114: 'CnnTextClassification.BuildGraph()' hides inherited member 'SciSharpExample.BuildGraph()'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword. [C:\Users\User\Documents\Projects\Internal\Vision\SciSharp-Stack-Examples-master\src\TensorFlowNET.Examples\TensorFlowNET.Examples.csproj]
The build failed. Fix the build errors and run again.
I get the same errors compiling in VisualStudio.
Using VS Version 16.7.5
I updated the NuGet packages too, no results.
Am I missing something?
Axl
https://github.com/SciSharp/SciSharp-Stack-Examples/blob/master/src/TensorFlowNET.Examples/ImageProcessing/ImageRecognitionInception.cs
我发现循环第一次的耗时永远比后面几次时间长,想问一下这是tf.Session().run()初次运行导致的吗
The FullyConnectedKeras
example in the TensorFlowNET.Examples
project runs properly with a target framework of net5.0
, with an accuracy around 95%. But if you change the target framework to net6.0
, the accuracy plummets to <10%. It isn't clear what the root cause is.
I discovered this when I tried to transplant this code to my .NET 6 project. It appears there is some sort of regression or bug that is tanking the accuracy in .NET 6 only.
Steps to Reproduce:
TargetFramework
of the TensorFlowNET.Examples
project from net5.0
to net6.0
.Fully Connected Neural Network (Keras)
example.0.098
.I have tried example in ImageClassificationKeras.cs and class_names in datasets are allways null. I tried to use explicit parameter - labels: "inferred", but it do not help.
Thank you
Milan B.
Hello ,
I have trained a SSD MobileNet V2 FPNLite 640x640 pretrained model in Tensorflow 2.4 with my own data and exported as saved model .The inference and image object detection prediction is working perfectly fine in python .
Im trying to do the same in Tensorflow.Net using the below code :
Session session = Session.LoadFromSavedModel(@"........\saved_model");
Tensor tensorNum = graph.OperationByName("num_detections");
Tensor tensorBoxes = graph.OperationByName("detection_boxes");
Tensor tensorScores = graph.OperationByName("detection_scores");
Tensor tensorClasses = graph.OperationByName("detection_classes");
Tensor imgTensor = graph.OperationByName("image_tensor");
Tensor[] outTensorArr = new Tensor[] { tensorNum, tensorBoxes, tensorScores, tensorClasses };
Im getting below weird error:
Tensorflow.ValueError: 'Could not find operation "num_detections" inside graph "grap-key-1/".'
I tried to loop the graph operations of the session but there is nothing in there .
Why this is happening ,it is the same model Im using in python and giving correct results .
Appreciate any help
Regards
Ayad
Hi!
I was just stepping through the example - one question regarding
Isn't it a typo that just the current members count of the dictionary is put into it?
My proposal would be:
word_dict[word.Word] = word.Count;
If it's just a wrong interpretation of me - ignore this and nevermind.
Regards
Sascha
PS: I think @Oceania2018 should be mentioned here :-)
Hi, I'm currently trying to use ImageRecognitionInception example using my own trained model. (which is a frozen inception .pb file) But here comes a problem.
** Unhandled exception. Tensorflow.InvalidArgumentError: Unknown image file format. One of JPEG, PNG, GIF, BMP required. [[{{node DecodeJpeg}}]]**
This happens even I used a right file format. I tried JPEG, PNG, JPG
(It worked well when I used a provided sample images and trained models)
I brought my own files from google drive. Is this could be a problem?
And also, can I fix this problem by changing my Exception Settings as well?
It would be so thankful if you give me some comments with this.
The Example AudioProcessing is Empty.
Can it be completed?
Anyone creating an example of an DQN/DDQN implementation?
Thanks!
很多错误,这是其中之一。
严重性 代码 说明 项目 文件 行 禁止显示状态
错误 CS0111 类型“CIFAR10_CNN”已定义了一个名为“Run”的具有相同参数类型的成员 TensorFlowNET.Examples C:\Users\47013\Desktop\临时\SciSharp-Stack-Examples-master\src\TensorFlowNET.Examples\ImageProcessing\ToyResNet.cs 43 活动
In vs2019 debug mode,after CnnInYourOwnData call Train() and running finished,it can generated all ckpt files
but then call Test() function : (loss_test, accuracy_test) = sess.run((loss, accuracy), (x, x_test), (y, y_test)); will auto interrupted without any information after some time;
if deleted next two lines
Test();
TestDataOutput();
and direct call function
FreezeModel();
public override string FreezeModel()
{
return tf.train.freeze_graph(Config.Name + @"\\MODEL", @".\\CNN_Best", new[]
{
"Input/X",
"Input/Y",
"Train/Prediction/predictions",
"Train/Prediction/prob"
});
}
will generate pb file, but the pb file is more less ckpt files,ckpt file more than 786M, and pb file is only 262M,using netron open pb and ckpt it show very defferent
thanks
Hello Masters!
Were you able to include the creation of pbtxt file from transfer Learning for image?
I tried the sample for transfer learning but the output label is text file and not same format from the pretrained models.
Thanks for anyone who would reply to my concern.
Hi
can anyone make ImageBackgroundRemoval example work?
I tried many things without success
can you please upload simple working code for Image Background Removal
Thanks
Hello, as per the subject, are there plans to implement TF2 functions?
For example:
tf.saved_model.load
This is part of the code I would like to implement in C# from python
image_np = load_image_into_numpy_array(image_path)
input_tensor = tf.convert_to_tensor(image_np)
input_tensor = input_tensor[tf.newaxis, ...]
detections = detect_fn(input_tensor)
num_detections = int(detections.pop('num_detections'))
detections = {key: value[0, :num_detections].numpy() for key, value in detections.items()}
detections['num_detections'] = num_detections
detections['detection_classes'] = detections['detection_classes'].astype(np.int64)
Some of this I can do, but now with TF2 being the standard (no frozen inference graph), it is difficult to proceed with building models in the old standard.
Just want to know if there are any plans as I cant find anything in the documentation that matches this use case from python.
Many thanks for your work so far.
I tried removing the reference, but most image manipulation examples fail with "reference not set to an instance of an object".
Any ideas?
Hi,
Is Deep Q Learning (Reinforcement Learning) supported by SciSharp? Because I can't find any example.
Thanks!
Hi,
I am interested in Keras Api using the Subclass style for building the model. I clone example and run example MNIST CNN (Keras Subclass).
I use save_weights
function but get errors as below.
Could you give any idea to save the model or weights? Thank you very much.
{
x_test = x_test["::100"];
y_test = y_test["::100"];
var pred = conv_net.Apply(x_test);
accuracy_test = (float)accuracy(pred, y_test);
print($"Test Accuracy: {accuracy_test}");
}
conv_net.save_weights("subclass_mnist_model"); // I added this
return accuracy_test > 0.90;
Choose one example to run, hit [Enter] to run all: 15
2021-09-08 오전 8:12:50 Starting MNIST CNN (Keras Subclass)
The file C:\Users\Quan\AppData\Local\Temp\mnist.npz already exists
2021-09-08 17:12:51.202274: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
step: 10, loss: 1.7204771, accuracy: 0.83
step: 20, loss: 1.5916963, accuracy: 0.898
step: 30, loss: 1.5561028, accuracy: 0.932
step: 40, loss: 1.5472074, accuracy: 0.944
step: 50, loss: 1.5292175, accuracy: 0.963
step: 60, loss: 1.507012, accuracy: 0.978
step: 70, loss: 1.5141329, accuracy: 0.968
step: 80, loss: 1.4908792, accuracy: 0.989
step: 90, loss: 1.4994849, accuracy: 0.978
Test Accuracy: 0.96
HDF5-DIAG: Error detected in HDF5 (1.10.5) thread 37204:
#000: C:\projects\hdf-pinvoke-1-10\CMake-hdf5-1.10.5\hdf5-1.10.5\src\H5L.c line 790 in H5Lexists(): not a location
major: Invalid arguments to routine
minor: Inappropriate type
#001: C:\projects\hdf-pinvoke-1-10\CMake-hdf5-1.10.5\hdf5-1.10.5\src\H5Gloc.c line 246 in H5G_loc(): invalid object ID major: Invalid arguments to routine
minor: Bad value
HDF5-DIAG: Error detected in HDF5 (1.10.5) thread 37204:
#000: C:\projects\hdf-pinvoke-1-10\CMake-hdf5-1.10.5\hdf5-1.10.5\src\H5D.c line 119 in H5Dcreate2(): not a location ID major: Invalid arguments to routine
minor: Inappropriate type
#001: C:\projects\hdf-pinvoke-1-10\CMake-hdf5-1.10.5\hdf5-1.10.5\src\H5Gloc.c line 246 in H5G_loc(): invalid object ID major: Invalid arguments to routine
minor: Bad value
HDF5CSharp.DataTypes.Hdf5Exception: Unable to create dataset for kernel:0
at HDF5CSharp.Hdf5Utils.GetId(Int64 parentId, String name, Int64 dataType, Int64 spaceId, Hdf5ElementType type)
at HDF5CSharp.Hdf5Utils.GetDatasetId(Int64 parentId, String name, Int64 dataType, Int64 spaceId)
at HDF5CSharp.Hdf5.WriteDatasetFromArray[T](Int64 groupId, String name, Array dset)
at Tensorflow.Keras.Saving.hdf5_format.WriteDataset(Int64 f, String name, Tensor data)
at Tensorflow.Keras.Saving.hdf5_format.save_weights_to_hdf5_group(Int64 f, List`1 layers)
at Tensorflow.Keras.Engine.Model.save_weights(String filepath, Boolean overwrite, String save_format, Object options) at TensorFlowNET.Examples.DigitRecognitionCnnKeras.Run() in E:\Tensorflow.Net\Keras.NetExample\src\TensorFlowNET.Examples\ImageProcessing\MnistCnnKerasSubclass.cs:line 97
at TensorFlowNET.Examples.Program.RunExamples(String key, IExample[] examples) in E:\Tensorflow.Net\Keras.NetExample\src\TensorFlowNET.Examples\Program.cs:line 89
2021-09-08 오전 8:13:20 Completed MNIST CNN (Keras Subclass) ++
Example: MNIST CNN (Keras Subclass) is Failed!
TensorFlow Binary v2.6.0
TensorFlow.NET v0.60.2.0
TensorFlow.Keras v0.6.2.0
1 of 27 example(s) are completed.
Press [Enter] to continue...
Hi all and you are amazing; this is a question.
I'm trying to create a simple function for my wpf project that remove background from a given image.
my relevant piece of code is:
'private static NumSharp.NDArray ReadTensorFromImageFile(string file_name,
int input_height = 224,
int input_width = 224,
int input_mean = 117,
int input_std = 1)
{
var graph = tf.Graph().as_default();
var file_reader = tf.read_file(file_name, "file_reader");
var decodeJpeg = tf.image.decode_jpeg(file_reader, channels: 3, name: "DecodeJpeg");
var cast = tf.cast(decodeJpeg, tf.float32);
var dims_expander = tf.expand_dims(cast, 0);
var resize = tf.constant(new int[] { input_height, input_width });
var bilinear = tf.image.resize_bilinear(dims_expander, resize);
var sub = tf.subtract(bilinear, new float[] { input_mean });
var normalized = tf.divide(sub, new float[] { input_std });
using (var sess = tf.Session(graph))
return sess.run(normalized);
}
public bool Run(string fileName)
{
var nd = ReadTensorFromImageFile(fileName);
var graph = new Graph();
graph.Import("frozen_inference_graph.pb");
Tensor output = graph.OperationByName("SemanticPredictions");
Tensor imgTensor = graph.OperationByName("ImageTensor");
using (var sess = tf.Session(graph))
{
var results = sess.run(output, new FeedItem(imgTensor, nd));
return true;
}
return false;
}
`
I got this error:
OverflowException: Overflow_Byte
NumSharp.Backends.Unmanaged.UnmanagedMemoryBlock.CastTo.AnonymousMethod__25(long) in UnmanagedMemoryBlock.Casting.cs
System.Threading.Tasks.Parallel.ForWorker64.AnonymousMethod__1()
System.Threading.Tasks.Task.InnerInvokeWithArg(System.Threading.Tasks.Task)
System.Threading.Tasks.Task.ExecuteSelfReplicating.AnonymousMethod__0(object)
what i'm doing wrong? (obviously lot of things...)
The unhandled System.AccessViolationException occurs , and I my try/catch cannot catch it.
What is the reason? How to fix it?
public bool Run()
{
PrepareData();
var graph = tf.Graph().as_default();
tf.train.import_meta_graph($"graph{Path.DirectorySeparatorChar}word2vec.meta"); //<---------Exception
System.AccessViolationException
HResult=0x80004003
Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
This is from the app console:
graph\word2vec.meta already exists.
word2vec\text8.zip already exists.
Words count: 17005207
Unique words: 253854
Vocabulary size: 47135
Most common words: UNK 0 444176, the 1 1061396, of 2 593677, and 3 416629, one 4 411764, in 5 372201, a 6 325873, to 7 316376, zero 8 264975, nine 9 250430
Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at Tensorflow.c_api.TF_ImportGraphDefOptionsSetPrefix(Tensorflow.SafeImportGraphDefOptionsHandle, System.String)
at Tensorflow.c_api.TF_ImportGraphDefOptionsSetPrefix(Tensorflow.SafeImportGraphDefOptionsHandle, System.String)
at Tensorflow.importer._PopulateTFImportGraphDefOptions(Tensorflow.ImportGraphDefOptions, System.String, System.Collections.Generic.Dictionary`2<System.String,Tensorflow.Tensor>, System.String[])
at Tensorflow.importer.import_graph_def(Tensorflow.GraphDef, System.Collections.Generic.Dictionary`2<System.String,Tensorflow.Tensor>, System.String[], System.String, Tensorflow.OpList)
at Tensorflow.meta_graph.import_scoped_meta_graph_with_return_elements(Tensorflow.MetaGraphDef, Boolean, System.String, System.Collections.Generic.Dictionary`2<System.String,Tensorflow.Tensor>, System.String, System.String[])
at Tensorflow.saver._import_meta_graph_with_return_elements(System.String, Boolean, System.String, System.String[])
at Tensorflow.tensorflow+train_internal.import_meta_graph(System.String, Boolean, System.String)
at TensorFlowNET.Examples.Word2Vec.Run()
at TensorFlowNET.Examples.Program.RunExamples(System.String, TensorFlowNET.Examples.IExample[])
at TensorFlowNET.Examples.Program.Main(System.String[])
module 'tensorflow.keras.preprocessing' has no attribute 'image_dataset_from_directory'
train_ds = tf.keras.preprocessing.image_dataset_from_directory(
data_dir,
validation_split=0.2,
subset="training",
seed=123,
image_size=(img_height, img_width),
batch_size=batch_size)
in image_classification.py
See public github repository for example:
https://github.com/Darlanio/SciSharp_TensorFlowNet_Missing_TrainableVariables
I was able to compile the SciSharp-Stack-Examples and run the GAN-example without too much trouble, by incorporating all necessary repositories from SciSharp into the same solution.
However, using the NuGet packages, the TrainableVariables referred to on lines 163-167 in the file
https://github.com/SciSharp/SciSharp-Stack-Examples/blob/master/src/TensorFlowNET.Examples/GAN/MnistGAN.cs
will not be found.
One other thing that is missing is the ToBitmap() in NDArray, line 227. I wrote another SaveImage() to bypass this problem.
Since the TrainableVariables are available in the SciSharp-repositories, I guess this will be fixed with the next version of the NuGet-packages?
The first four examples work, the rest crash on two different computers - both running with fresh VS2019 installs. Is that to be expected, or did I miss something? Are we in between two working releases?
Example: Hello World in 0,0848558s is OK!
Example: Basic Operations in 0,1338481s is OK!
Example: NN XOR in 0,000847s is OK!
Example: Linear Regression in 1,1675918s is OK!
Example: Logistic Regression is Failed!
Example: Naive Bayes Classifier is Failed!
Example: Nearest Neighbor is Failed!
Example: Digits Recognition Neural Network is Failed!
Example: MNIST CNN is Failed!
Example: MNIST RNN is Failed!
Example: MNIST LSTM is Failed!
Example: CnnInYourOwnData is Failed!
Example: Fully Connected Neural Network is Failed!
Example: Convert TensorFlow Model to OpenCv is Failed!
Example: Image Recognition Inception is Failed!
Example: Retrain Classifier With InceptionV3 is Failed!
Example: Object Detection is Failed!
Example: CNN Text Classification is Failed!
Example: Word2Vec is Failed!
I'm including the log file.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.