NetExternalObject

NetExternalObject[]

表示外部框架格式中的网络模型.

更多信息

  • NetExternalObject 通常在使用 Wolfram 语言未定义的神经网络模型时运行推断.
  • 支持的文件格式有:
  • "ONNX"ONNX 模型
    "MXNet"MXNet 模型
    "GGUF"GGUF 模型
  • 对于只有一个输入端口的模型,NetExternalObject[][data] 给出对 data 应用模型的结果.
  • 对于有多个输入端口的模型,NetExternalObject[][<|port1data1,|>]datai 提供给 porti.
  • NumericArray 形式给出 data 时,输出将会是 NumericArray. »
  • Information[NetExternalObject[]] 生成一个关于模型的信息面板. »
  • NetExternalObjectInformation 可能包括以下属性:
  • "Backend"the evaluation back end used by the model
    "ContextWindowSize"current maximum size of the model context windows
    "InputPortNames"输入端口的名称列表
    "InputPorts"输入端口形状的关联
    "OutputPortNames"输出端口的名称列表
    "OutputPorts"输出端口形状的关联
    "Properties"可用属性
    "RawData"未处理的模型的原始内容
    "TrainingContextWindowSize"original size of the model context windows
  • NetExternalObject[][data,opts] 指定在对 data 应用网络时应使用的选项. 可能的选项包括:
  • Method Automaticspecify details of the model evaluation
    TargetDevice "CPU"进行运算的设备
  • TargetDevice 可取的设置取决于系统和硬件,其中包括:
  • "CPU"使用 CPU
    "GPU"使用可用的专用硬件
    "CoreML"Apple CoreML 框架
    "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"Automaticmaximum number of generated tokens
    RandomSeedingAutomaticwhat seeding of pseudorandom generators should be done internally
    "PrependPrompt"Falsewhether to prepend the input to ext to the output text
    "ResetState"Truewhether to reset the language model's state before processing the input
    "StopTokens"{}a list of strings that should stop the generation if produced

范例

打开所有单元关闭所有单元

基本范例  (2)

将 ONNX 模型导入为外部网络:

在一些输入数据上对模型进行运算:

导入量化图像分类器:

定义一个最简流程对数据进行预处理和后处理:

运行外部模型:

范围  (5)

格式  (3)

将 ONNX 模型导入为 NetExternalObject

Import a net in GGUF format (model credit: Olusegun Odewole, https://huggingface.co/segestic/Tinystories-gpt-0.1-3m ):

将 MXNet 模型导入为 NetExternalObject

属性  (2)

Information 提取外部网络的属性:

获取属性列表:

获取所有支持的属性的列表:

选项  (4)

Method  (2)

Import a text-generating model:

Run the model until a termination token is reached:

Prepend the prompt to the generated text:

Specify a maximum amount of tokens to generate:

Text generation is a random process:

Fix the seed of the pseudorandom generator to get reproducible results:

TargetDevice  (2)

导入 ONNX 模型作为外部网络:

用 CoreML 运行模型:

在专用硬件上计算时,某些模型会运行得更快:

CPU 上的用时:

CoreML 上的用时:

应用  (3)

运行实时人脸检测器:

定义从图像到数组列表的转换:

在编码图像上运行检测器:

从结果中提取边界框和概率信息:

可视化检测,滤掉概率低或过度重叠的检测:

该网络可以在消费类笔记本电脑上每秒分析超过 40 张图像:

Import a text-generating model:

Run the model until a termination token is reached:

Import a "GGUF" file as an embedding model:

Generate an embedding vector for each token in a string:

属性和关系  (2)

NumericArray 形式给出输入将使输出也是一个 NumericArray

外部网络模型通常含有硬编码的批量维度:

普通网络没有明确的批量维度:

它们适用于单个样例和任意大小的批次:

可能存在的问题  (2)

无法修改外部模型:

无法重新训练外部模型:

Wolfram Research (2022),NetExternalObject,Wolfram 语言函数,https://reference.wolfram.com/language/ref/NetExternalObject.html (更新于 2025 年).

文本

Wolfram Research (2022),NetExternalObject,Wolfram 语言函数,https://reference.wolfram.com/language/ref/NetExternalObject.html (更新于 2025 年).

CMS

Wolfram 语言. 2022. "NetExternalObject." Wolfram 语言与系统参考资料中心. Wolfram Research. 最新版本 2025. https://reference.wolfram.com/language/ref/NetExternalObject.html.

APA

Wolfram 语言. (2022). NetExternalObject. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/ref/NetExternalObject.html 年

BibTeX

@misc{reference.wolfram_2025_netexternalobject, author="Wolfram Research", title="{NetExternalObject}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/NetExternalObject.html}", note=[Accessed: 07-June-2025 ]}

BibLaTeX

@online{reference.wolfram_2025_netexternalobject, organization={Wolfram Research}, title={NetExternalObject}, year={2025}, url={https://reference.wolfram.com/language/ref/NetExternalObject.html}, note=[Accessed: 07-June-2025 ]}