![]() |
MyCaffe
1.12.2.41
Deep learning software for Windows C# programmers.
|
The PythonInterop uses PythonNet to execute Python code. More...
Public Member Functions | |
| PythonInterop (string strPythonDllPath) | |
| The constructor. More... | |
| void | Dispose () |
| Free all resources used. More... | |
| void | Initialize (string strPythonDllPath) |
| Initialize the Python Engine with the version of Python used. More... | |
| void | Shutdown () |
| Shutdown the Python engine. More... | |
| void | RunPythonCode (string pycode) |
| Run the Python code specified. More... | |
| void | RunPythonCode (string pycode, object parameter, string parameterName) |
| Run the Python code specified, passing a parameter to it from C# More... | |
| object | RunPythonCodeAndReturn (string pycode, object parameter, string parameterName, string returnedVariableName) |
| Run the Python code specified, passing a parameter to it from C# and receiving a return value More... | |
| object | RunPythonCodeAndReturn (string pycode, string returnedVariableName, params KeyValuePair< string, object >[] rgArg) |
| Run the Python code specified, passing a set of parameters to it from C# and receiving a return value More... | |
| Dictionary< string, object > | ConvertToDictionary (object obj) |
| Convert the Python object to a CLR dictionary. More... | |
The PythonInterop uses PythonNet to execute Python code.
Definition at line 21 of file PythonInterop.cs.
| MyCaffe.python.PythonInterop.PythonInterop | ( | string | strPythonDllPath | ) |
The constructor.
| strPythonDllPath | Specifies the path to the Python DLL (e.g. Python39.dll) which is usually located at: @"C:\Users\" + strUserName + @"\AppData\Local\Programs\Python\Python39\python39.dll"
|
See https://github.com/MyCaffe/MyCaffe/blob/master/MyCaffe.app/FormGptTest.cs (dowork, line 85) for an example that demonstrates how to use the PythonInterop class to run the GPT2 pre-trained model from HuggingFace to generate text.
Definition at line 36 of file PythonInterop.cs.
| Dictionary< string, object > MyCaffe.python.PythonInterop.ConvertToDictionary | ( | object | obj | ) |
Convert the Python object to a CLR dictionary.
| obj | Specifies the PyObject returned by python. |
| Exception | Exception thrown when 'obj' is not a PyObject type. |
Definition at line 161 of file PythonInterop.cs.
| void MyCaffe.python.PythonInterop.Dispose | ( | ) |
Free all resources used.
Definition at line 44 of file PythonInterop.cs.
| void MyCaffe.python.PythonInterop.Initialize | ( | string | strPythonDllPath | ) |
Initialize the Python Engine with the version of Python used.
| strPythonDllPath | Specifies the path to the Python DLL (e.g. Python39.dll) which is usually located at: @"C:\Users\" + strUserName + @"\AppData\Local\Programs\Python\Python39\python39.dll"
|
Definition at line 57 of file PythonInterop.cs.
| void MyCaffe.python.PythonInterop.RunPythonCode | ( | string | pycode | ) |
Run the Python code specified.
| pycode | Specifies a block of Python code to run. |
Definition at line 75 of file PythonInterop.cs.
| void MyCaffe.python.PythonInterop.RunPythonCode | ( | string | pycode, |
| object | parameter, | ||
| string | parameterName | ||
| ) |
Run the Python code specified, passing a parameter to it from C#
| pycode | Specifies a block of Python code to run. |
| parameter | Specifies the parameter value. |
| parameterName | Specifies the parameter name within the Python code. |
Definition at line 89 of file PythonInterop.cs.
| object MyCaffe.python.PythonInterop.RunPythonCodeAndReturn | ( | string | pycode, |
| object | parameter, | ||
| string | parameterName, | ||
| string | returnedVariableName | ||
| ) |
Run the Python code specified, passing a parameter to it from C# and receiving a return value
| pycode | Specifies a block of Python code to run. |
| parameter | Specifies the parameter value. |
| parameterName | Specifies the parameter name within the Python code. |
| returnedVariableName | Specifies the name of the return value in the Python code. |
Definition at line 110 of file PythonInterop.cs.
| object MyCaffe.python.PythonInterop.RunPythonCodeAndReturn | ( | string | pycode, |
| string | returnedVariableName, | ||
| params KeyValuePair< string, object >[] | rgArg | ||
| ) |
Run the Python code specified, passing a set of parameters to it from C# and receiving a return value
| pycode | Specifies a block of Python code to run. |
| returnedVariableName | Specifies the name of the return value in the Python code. |
| rgArg | Specifies a list of parameter name, value pairs. |
Definition at line 132 of file PythonInterop.cs.
| void MyCaffe.python.PythonInterop.Shutdown | ( | ) |
Shutdown the Python engine.
Definition at line 66 of file PythonInterop.cs.