SciSharp / SciSharp-Stack-Examples

Practical examples written in SciSharp's machine learning libraries
http://scisharpstack.org
Apache License 2.0
313 stars 100 forks source link

Word2Vec: System.AccessViolationException #26

Closed ZedZipDev closed 3 years ago

ZedZipDev commented 3 years ago

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[])
Oceania2018 commented 3 years ago

image

Nucs commented 3 years ago

Related to https://github.com/SciSharp/TensorFlow.NET/issues/380