Giter Club home page Giter Club logo

gradient-samples's Introduction

TensorFlow C# samples

Samples for LostTech.TensorFlow, TensorFlow binding for .NET

BasicMath (v1) - creates two constant tensors and performs simple algebraic operations on them

CharRNN - the sample was removed from 2.x samples, as it only works with TensorFlow 1.15. The old version is still available in 1.15 branch.

CSharpOrNot - a mini-ResNet convolutional network, that guesses programming language, given a rectangular text block from a code file. Has a cross-platform UI demo. Get pretrained model here: https://github.com/losttech/Gradient-Samples/releases/tag/csharp-or-not%2Fv1

FashionMnistClassification - standard TensorFlow example, that classifies small pictures of clothes.

ResNetBlock - same as FashionMnistClassification above, but shows Model subclassing to implement ResNet block.

RL-MLAgents - reinforcement learning agent, that learns to play Unity 3D based games using Soft Actor-Critic algorithm, and Unity ML agents library. More details in the blog post.

SimpleApproximation - uses a simple 1 hidden layer neural network to approximate an arbitrary function.

All models can be modified and trained.

LICENSE - MIT for all sample code, individual samples might have different licenses (clearing that up, see individual sample folders).

Larger samples (in separate repositories)

GPT-2 - latest published English language model from OpenAI with fine-tuning from https://github.com/nshepperd/gpt-2.

SIREN - neural representation for any kind of signal (image, video, audio).

YOLOv4 - neural network for object detection.

Billion Songs - deep learning-powered song lyrics generator in an ASP.NET Core web site. More details in Writing billion songs with C# and Deep Learning.

gradient-samples's People

Contributors

lostmsu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gradient-samples's Issues

Access Denied errors in download scripts for GPT-2

OpenAI has moved its datasets to Azure, the google cloud URLs are no longer working for downloading the GPT-2 datasets.

Lines that need to be updated:

curl --output models/$fetch https://storage.googleapis.com/gpt-2/models/$fetch

Invoke-WebRequest -OutFile "models/$fetch" -Uri "https://storage.googleapis.com/gpt-2/models/$fetch"

https://storage.googleapis.com/gpt-2/models/$fetch should be https://openaipublic.azureedge.net/gpt-2/models/$fetch.

See openai/gpt-2-output-dataset@2c10240

GPT-2 sampling fails on CPU

InvalidArgumentError : indices[0,0] = 1024 is not in [0, 1024)

Looks like an off-by-one error.

Here are the exception details:

Python.Runtime.PythonException
HResult=0x80131500
Message=InvalidArgumentError : indices[0,0] = 1024 is not in [0, 1024)
[[Node: sample_sequence/while/model/GatherV2_1 = GatherV2[Taxis=DT_INT32, Tindices=DT_INT32, Tparams=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"](sample_sequence/while/model/GatherV2_1/Enter, sample_sequence/while/model/ExpandDims, sample_sequence/while/model/h11/attn/range_1/start, ^sample_sequence/while/strided_slice/stack_2)]]

Caused by op 'sample_sequence/while/model/GatherV2_1', defined at:
File "C:\Users<SCRAMBLED>\AppData\Local\conda\conda\envs\tf\lib\site-packages\tensorflow\python\ops\control_flow_ops.py", line 3232, in while_loop
return_same_structure)
File "C:\Users<SCRAMBLED>\AppData\Local\conda\conda\envs\tf\lib\site-packages\tensorflow\python\ops\control_flow_ops.py", line 2952, in BuildLoop
pred, body, original_loop_vars, loop_vars, shape_invariants)
File "C:\Users<SCRAMBLED>\AppData\Local\conda\conda\envs\tf\lib\site-packages\tensorflow\python\ops\control_flow_ops.py", line 2887, in _BuildLoop
body_result = body(*packed_vars_for_body)
File "C:\Users<SCRAMBLED>\AppData\Local\conda\conda\envs\tf\lib\site-packages\tensorflow\python\ops\control_flow_ops.py", line 3201, in
body = lambda i, lv: (i + 1, orig_body(*lv))
File "C:\Users<SCRAMBLED>\AppData\Local\conda\conda\envs\tf\lib\site-packages\tensorflow\python\ops\array_ops.py", line 2659, in gather
return gen_array_ops.gather_v2(params, indices, axis, name=name)
File "C:\Users<SCRAMBLED>\AppData\Local\conda\conda\envs\tf\lib\site-packages\tensorflow\python\ops\gen_array_ops.py", line 3761, in gather_v2
"GatherV2", params=params, indices=indices, axis=axis, name=name)
File "C:\Users<SCRAMBLED>\AppData\Local\conda\conda\envs\tf\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 787, in _apply_op_helper
op_def=op_def)
File "C:\Users<SCRAMBLED>\AppData\Local\conda\conda\envs\tf\lib\site-packages\tensorflow\python\util\deprecation.py", line 454, in new_func
return func(*args, **kwargs)
File "C:\Users<SCRAMBLED>\AppData\Local\conda\conda\envs\tf\lib\site-packages\tensorflow\python\framework\ops.py", line 3155, in create_op
op_def=op_def)
File "C:\Users<SCRAMBLED>\AppData\Local\conda\conda\envs\tf\lib\site-packages\tensorflow\python\framework\ops.py", line 1717, in init
self._traceback = tf_stack.extract_stack()

InvalidArgumentError (see above for traceback): indices[0,0] = 1024 is not in [0, 1024)
[[Node: sample_sequence/while/model/GatherV2_1 = GatherV2[Taxis=DT_INT32, Tindices=DT_INT32, Tparams=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"](sample_sequence/while/model/GatherV2_1/Enter, sample_sequence/while/model/ExpandDims, sample_sequence/while/model/h11/attn/range_1/start, ^sample_sequence/while/strided_slice/stack_2)]]

Source=Python.Runtime
StackTrace:
[' File "C:\Users\\AppData\Local\conda\conda\envs\tf\lib\site-packages\tensorflow\python\client\session.py", line 877, in run\n run_metadata_ptr)\n', ' File "C:\Users\\AppData\Local\conda\conda\envs\tf\lib\site-packages\tensorflow\python\client\session.py", line 1100, in _run\n feed_dict_tensor, options, run_metadata)\n', ' File "C:\Users\\AppData\Local\conda\conda\envs\tf\lib\site-packages\tensorflow\python\client\session.py", line 1272, in _do_run\n run_metadata)\n', ' File "C:\Users\\AppData\Local\conda\conda\envs\tf\lib\site-packages\tensorflow\python\client\session.py", line 1291, in _do_call\n raise type(e)(node_def, op, message)\n']

CharRNN has a TypeInitializationException

System.TypeInitializationException
  HResult=0x80131534
  Message=The type initializer for 'numpy.np' threw an exception.
  Source=LostTech.NumPy
  StackTrace:
   at numpy.np.array(Object object, Object dtype, Boolean copy, String order, Boolean subok, Int32 ndmin)
   at CharRNN.TextLoader.Preprocess(String inputFile, String vocabularyFile, String tensorFile, IEnumerable`1& chars, Dictionary`2& vocabulary) in C:\Users\SnowSnakz\Downloads\Gradient-Samples-master\Gradient-Samples-master\CharRNN\CharRNNUtils.cs:line 52
   at CharRNN.TextLoader..ctor(String dataDir, Int32 batchSize, Int32 seqLength, Encoding encoding) in C:\Users\SnowSnakz\Downloads\Gradient-Samples-master\Gradient-Samples-master\CharRNN\CharRNNUtils.cs:line 35
   at CharRNN.CharRNNProgram.Train(CharRNNTrainingParameters args) in C:\Users\SnowSnakz\Downloads\Gradient-Samples-master\Gradient-Samples-master\CharRNN\CharRNNProgram.cs:line 55
   at CharRNN.CharRNNProgram.<>c.<Main>b__2_0(CharRNNTrainingParameters train) in C:\Users\SnowSnakz\Downloads\Gradient-Samples-master\Gradient-Samples-master\CharRNN\CharRNNProgram.cs:line 27
   at CharRNN.CharRNNProgram.Main(String[] args) in C:\Users\SnowSnakz\Downloads\Gradient-Samples-master\Gradient-Samples-master\CharRNN\CharRNNProgram.cs:line 25

Inner Exception 1:
ArgumentNullException: Value cannot be null.
Parameter name: source

This occurs with a fresh download.

System.TypeInitializationException:“The type initializer for 'fashion_mnist' threw an exception.”

PS D:\github> git clone https://github.com/losttech/Gradient-Samples.git
Cloning into 'Gradient-Samples'...
remote: Enumerating objects: 1765, done.
remote: Counting objects: 100% (282/282), done.
remote: Compressing objects: 100% (64/64), done.
remote: Total 1765 (delta 253), reused 224 (delta 214), pack-reused 1483Receiving objects: 99% (1748/1765)
Receiving objects: 100% (1765/1765), 690.92 KiB | 1.52 MiB/s, done.
Resolving deltas: 100% (1176/1176), done.

Open FashionMnistClassification.csproj and run

System.TypeInitializationException
HResult=0x80131534
Message=The type initializer for 'fashion_mnist' threw an exception.
Source=LostTech.TensorFlow
StackTrace:
在 tensorflow.tf.keras.datasets.fashion_mnist.load_data()
在 LostTech.Gradient.Samples.FashionMnistClassification.Main() 在 D:\Github\Gradient-Samples\FashionMnistClassification\FashionMnistClassification.cs 中: 第 17 行

此异常最初是在此调用堆栈中引发的:
[外部代码]

内部异常 1:
GradientInitializationException: None of discovered matching Python environments have TensorFlow 2.* installed. Please, install tensorflow or tensorflow-gpu 2.5.*, or use GradientEngine to configure Python home to use a different environment.

Found Python:
3.10-X64 at C:\Python310\

(dynamic train, dynamic test) = tf.keras.datasets.fashion_mnist.load_data();

Q: Where is the data of fashion_mnist?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.