NetExternalObject
represents a net model in an external framework format.
Details
- NetExternalObject is typically used to run inference using neural network models not defined in the Wolfram Language.
- Supported file formats are:
-
"ONNX" ONNX models "MXNet" MXNet models "GGUF" GGUF models - For a model with a single input port, NetExternalObject[…][data] gives the result of applying the model to data.
- For a model with multiple input ports, NetExternalObject[…][<port1data1,… >] provides datai to porti.
- When data is given as NumericArray, the output will be a NumericArray. »
- Information[NetExternalObject[…]] generates an information panel about the model. »
- Information of a NetExternalObject may include the following properties:
-
"Backend" the evaluation back end used by the model "ContextWindowSize" current maximum size of the model context windows "InputPortNames" list of names of input ports "InputPorts" association of input port shapes "OutputPortNames" list of names of output ports "OutputPorts" association of output port shapes "Properties" available properties "RawData" unprocessed native contents of the model "TrainingContextWindowSize" original size of the model context windows - NetExternalObject[…][data,opts] specifies that options should be used in applying the net to data. Possible options include:
-
Method Automatic specify details of the model evaluation TargetDevice "CPU" the device on which to perform evaluation - Possible settings for TargetDevice change depending on the system and the hardware and include:
-
"CPU" use the CPU "GPU" use available dedicated hardware "CoreML" Apple CoreML framework "CUDA" Nvidia CUDA API "DirectML" Microsoft Direct Machine Learning API - For a NetExternalObject with LLaMA.cpp backend ("GGUF" format) that generates text, option Method can be set to a list of rules having any of the following keys:
-
"MaxTokens" Automatic maximum number of generated tokens RandomSeeding Automatic what seeding of pseudorandom generators should be done internally "PrependPrompt" False whether to prepend the input to ext to the output text "ResetState" True whether to reset the language model's state before processing the input "StopTokens" {} a list of strings that should stop the generation if produced
Examples
open allclose allBasic Examples (2)
Scope (5)
Formats (3)
Import an ONNX model as a NetExternalObject:
Import a net in GGUF format (model credit: Olusegun Odewole, https://huggingface.co/segestic/Tinystories-gpt-0.1-3m ):
Import an MXNet model as a NetExternalObject:
Properties (2)
Extract a property of the external net using Information:
Options (4)
Method (2)
Applications (3)
Run a real-time face detector:
Define a transformation from an image to a list of arrays:
Run the detector on the encoded image:
Extract the bounding box and probability information from the result:
Visualize the detections, filtering the ones with low probability or large overlap:
This network can analyze more that 40 images per second on a consumer laptop:
Import a text-generating model:
Run the model until a termination token is reached:
Import a "GGUF" file as an embedding model:
Properties & Relations (2)
Input given as a NumericArray will cause the output to also be a NumericArray:
External net models typically have a hard-coded batch dimension:
Text
Wolfram Research (2022), NetExternalObject, Wolfram Language function, https://reference.wolfram.com/language/ref/NetExternalObject.html (updated 2025).
CMS
Wolfram Language. 2022. "NetExternalObject." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2025. https://reference.wolfram.com/language/ref/NetExternalObject.html.
APA
Wolfram Language. (2022). NetExternalObject. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/NetExternalObject.html