小编Ara*_*atK的帖子

如何将protobuf图转换为二进制线格式?

我有一种方法将二进制有线格式转换为人类可读的格式,但我无法做到这一点

import tensorflow as tf
from tensorflow.python.platform import gfile

def converter(filename): 
  with gfile.FastGFile(filename,'rb') as f:
    graph_def = tf.GraphDef()
    graph_def.ParseFromString(f.read())
    tf.import_graph_def(graph_def, name='')
    tf.train.write_graph(graph_def, 'pbtxt/', 'protobuf.pb', as_text=True)
  return
Run Code Online (Sandbox Code Playgroud)

我只需要为此输入文件名,它就可以了.但是我做了相反的事情

  File "pb_to_pbtxt.py", line 16, in <module>
    converter('protobuf.pb')  # here you can write the name of the file to be converted
  File "pb_to_pbtxt.py", line 11, in converter
    graph_def.ParseFromString(f.read())
  File "/usr/local/lib/python2.7/dist-packages/google/protobuf/message.py", line 185, in ParseFromString
    self.MergeFromString(serialized)
  File "/usr/local/lib/python2.7/dist-packages/google/protobuf/internal/python_message.py", line 1008, in MergeFromString
    if self._InternalParse(serialized, 0, length) != length:
  File "/usr/local/lib/python2.7/dist-packages/google/protobuf/internal/python_message.py", line 1034, in InternalParse
    new_pos …
Run Code Online (Sandbox Code Playgroud)

python protocol-buffers python-2.7 tensorflow

8
推荐指数
1
解决办法
2595
查看次数

无法使用cgo CFLAGS

我手动克隆了tensorflow的go目录(我正在处理的库), /home/arafat/go/src/github.com/tensorflow/tensorflow/tensorflow/contrib/go你可以看看这里.我已将lib.go更改为

// #cgo LDFLAGS: -ltensorflow
// #cgo CFLAGS: -I /home/arafat/go/src/github.com/tensorflow/tensorflow
// #cgo CXXFLAGS: -I /home/arafat/go/src/github.com/tensorflow/tensorflow -std=c++11
Run Code Online (Sandbox Code Playgroud)

但是我收到了错误

# github.com/tensorflow/tensorflow/tensorflow/contrib/go
In file included from go/src/github.com/tensorflow/tensorflow/tensorflow/contrib/go/tf_session_helper.cc:20:0:
go/src/github.com/tensorflow/tensorflow/tensorflow/contrib/go/tf_session_helper.h:22:49: fatal error: tensorflow/core/public/tensor_c_api.h: No such file or directory
 #include "tensorflow/core/public/tensor_c_api.h"
                                                 ^
compilation terminated.
Run Code Online (Sandbox Code Playgroud)

在做

go get github.com/tensorflow/tensorflow/tensorflow/contrib/go
Run Code Online (Sandbox Code Playgroud)

我无法理解为什么这不起作用.

go cflags

7
推荐指数
1
解决办法
701
查看次数

自动更正库中的行长度

我正在开发一个庞大的项目,我们决定让所有代码符合每行80个字符.它是一个基于ruby的项目,带有C的包装器.对于Ruby,我决定使用Rubocop并使用命令:

rubocop --only LineLength
Run Code Online (Sandbox Code Playgroud)

我得到了1,714个错误,其中行的长度大于80个字符.除此之外,还有许多Rubocop检测到的其他错误,我现在想忽略它们.

我要寻找到自动纠正所有的线路长度违反最简单的方法,以满足无论是在C和红宝石的80个字符的限制.

ruby syntax rubocop

6
推荐指数
1
解决办法
969
查看次数

使用Swig将std :: set转换为ruby

我正在使用Swig在ruby中使用C++.目前我已经完成了一个文件david.h的简单示例

#include <stdio.h>
class David
{
public:
    David(int x)
    {
        this->x = x;
    }
    void announce()
    {
        printf("David %d\n", x);
    }
    int x;
};
Run Code Online (Sandbox Code Playgroud)

还有另一个像swig这样的文件

%module "david"
%{
#include <libdavid.h>
%}
class David
{
public:
    David(int x);
    void announce();
    int x;
};
Run Code Online (Sandbox Code Playgroud)

extconf.rb看起来像这样

require 'mkmf'
system('swig -c++ -ruby libdavid.i') or abort
create_makefile('david')
Run Code Online (Sandbox Code Playgroud)

这有助于我像这样在ruby中执行一个非常简单的例子

2.2.1 :001 > a=David::David.new(42)
 => #<David::David:0x000000022c3ec0 @__swigtype__="_p_David"> 
2.2.1 :002 > a.x
 => 42 
Run Code Online (Sandbox Code Playgroud)

现在,我已经非常努力了一段时间,但现在我根本想不通如实例给出了如何使用来自C++ STL设置在这里.如果有人可以帮我解决我如何创建一组整数或者矢量并展示如何在该集合/向量上插入和擦除方法,那将是非常好的.简单的代码示例不仅对我而且对于将来可能面临这种情况的许多人来说非常有用.


如果你很忙,这只是个人要求随意跳过这个.
说实话,我已经使用堆栈溢出了很长一段时间,但慢慢地我开始对社区感到失望.我一直在发几个问题,我没有得到满意的答案,没有上升票,没有下来投票,没有,我只是没有收到任何答案.让我感到惊讶的是,在简单的谷歌搜索中可以回答的非常微不足道的问题通常非常受欢迎,新用户的重要问题要么被严重投票,要么被完全忽略.我知道社区不会对我说任何事情.但如果有人可以解释可能的原因,我将非常感激.

谢谢

c++ ruby swig stl

6
推荐指数
1
解决办法
227
查看次数

如何在 extconf.rb 中为 SWIG 正确包含库路径和其他标志?

假设我要用命令编译一个 C 文件

g++ a.cpp  -I/usr/local/gr/include -L/usr/local/gr/lib -lGR -lm -Wl,-rpath,/usr/local/gr/lib
Run Code Online (Sandbox Code Playgroud)

我将如何在 SWIG 中定义 extconf.rb 文件,以便它不会忽略链接器路径?
这是我当前的 extconf.rb 文件。

require 'mkmf'
system('swig -c++ -ruby example.i') or abort
$CXXFLAGS += " -I/usr/local/gr/include -L/usr/local/gr/lib -lGR -lm -Wl,-rpath,/usr/local/gr/lib "
create_makefile('example')
Run Code Online (Sandbox Code Playgroud)

它忽略带有错误的链接器标志

clang: warning: -lGR: 'linker' input unused [-Wunused-command-line-argument]
clang: warning: -lm: 'linker' input unused [-Wunused-command-line-argument]
clang: warning: -Wl,-rpath,/usr/local/gr/lib: 'linker' input unused [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-L/usr/local/gr/lib' [-Wunused-command-line-argument]
Run Code Online (Sandbox Code Playgroud)

ruby binding swig ff

5
推荐指数
1
解决办法
412
查看次数

标签 统计

ruby ×3

swig ×2

binding ×1

c++ ×1

cflags ×1

ff ×1

go ×1

protocol-buffers ×1

python ×1

python-2.7 ×1

rubocop ×1

stl ×1

syntax ×1

tensorflow ×1