dll – 使用C API的“Hello TensorFlow!”
发布时间:2020-12-14 01:59:43 所属栏目:Windows 来源:网络整理
导读:出于学习目的,如何使用TensorFlow C API对此 Python示例进行编码? import tensorflow as tfhello = tf.constant("hello TensorFlow!")sess=tf.Session()print(sess.run(hello)) 我这样试过: #include string.h#include iostream.h#include "c_api.h"int ma
出于学习目的,如何使用TensorFlow C API对此
Python示例进行编码?
import tensorflow as tf hello = tf.constant("hello TensorFlow!") sess=tf.Session() print(sess.run(hello)) 我这样试过: #include <string.h> #include <iostream.h> #include "c_api.h" int main( int argc,char ** argv ) { TF_Graph * graph = TF_NewGraph(); TF_SessionOptions * options = TF_NewSessionOptions(); TF_Status * status = TF_NewStatus(); TF_Session * session = TF_NewSession( graph,options,status ); char hello[] = "Hello TensorFlow!"; TF_Tensor * tensor = TF_AllocateTensor( TF_STRING,8 + TF_StringEncodedSize( strlen( hello ) ) ); TF_OperationDescription * operationDescription = TF_NewOperation( graph,"Const","hello" ); TF_Operation * operation; struct TF_Output * output; TF_StringEncode( hello,strlen( hello ),8 + ( char * ) TF_TensorData( tensor ),TF_StringEncodedSize( strlen( hello ) ),status ); TF_SetAttrTensor( operationDescription,"value",tensor,status ); TF_SetAttrType( operationDescription,"dtype",TF_TensorType( tensor ) ); operation = TF_FinishOperation( operationDescription,status ); output->oper = operation; output->index = 0; TF_SessionRun( session,// Inputs output,&tensor,1,// Outputs &operation,// Operations 0,status ); printf( "%i",TF_GetCode( status ) ); TF_CloseSession( session,status ); TF_DeleteSession( session,status ); TF_DeleteStatus( status ); TF_DeleteSessionOptions( options ); return 0; } 我在Windows上使用TensorFlow.dll测试它: 上面的代码GPF在TF_SessionRun()上调用.一旦我们找到了解决方案,如何检索输出?应该使用不同的张量 非常感谢 解决方法
偏移初始化旁边有一个要解决的错误.这个版本似乎工作正常:
#include <iostream.h> #include "c_api.h" int main( int argc,8 + TF_StringEncodedSize( strlen( hello ) ) ); TF_Tensor * tensorOutput; TF_OperationDescription * operationDescription = TF_NewOperation( graph,"hello" ); TF_Operation * operation; struct TF_Output output; TF_StringEncode( hello,status ); memset( TF_TensorData( tensor ),8 ); TF_SetAttrTensor( operationDescription,status ); output.oper = operation; output.index = 0; TF_SessionRun( session,// Inputs &output,&tensorOutput,status ); printf( "status code: %in",TF_GetCode( status ) ); printf( "%sn",( ( char * ) TF_TensorData( tensorOutput ) ) + 9 ); TF_CloseSession( session,status ); TF_DeleteStatus( status ); TF_DeleteSessionOptions( options ); return 0; } 我们必须删除tensorOutput吗?不知道为什么我们必须添加9(而不是8)来获得字符串的开头. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 在Windows 7下从VB6运行activex dll
- windows – 刻录50台计算机而不在每台计算机上安装操作系统
- windows-server-2003 – 在Windows Server 2003上启用SHA2证
- 发布到IIS.省略在服务器上安装.NET Core Windows Server Ho
- azure-storage – 在Windows Azure Blob存储中使用子目录
- windows – 每个线程如何拥有CPU寄存器
- Windows 2012安装mysql 5.7.22 企业版
- 定时任务:windows下备份数据文件到指定的目录
- windows-server-2008 – Powershell使用CNAME远程连接到服务
- Windows 7的任务栏(启用了MainFormOnTaskbar)的Delphi窗体图
推荐文章
站长推荐
- IIS+PHP+MySQL+Zend?Optimizer+GD库+phpMyAdmin安
- windows-7 – 无法看到我在telnet中输入的内容
- Windows Server 2016-部署第一台域控制器
- windows-phone-8.1 – 如何检测在Windows 10 Mob
- microsoft-metro – 地铁式应用中的RSA加密
- 在Windows XP上使用java web start(jnlp)和几个j
- 在Windows 8 Metro App(C#/ XAML)中同时播放两个
- windows-7 – 如何准备更换/升级主板
- windows-server-2008 – 在Windows Server防火墙
- qt – 使用QML保存窗口状态
热点阅读