Tensorboard C ++ API构建失败

时间:2018-06-25 02:01:38

标签: tensorflow tensorboard

我正在尝试构建一个使用Tensorboard的简单程序(./src/histogram.cpp)(如该线程中的显示:https://github.com/coreybutler/nvm-windows#usage):

// This file runs the tensorboard histogram profiler.

#include <string>
#include <chrono>
#include <iostream>

#include <tensorflow/core/util/events_writer.h>

namespace tf = tensorflow;

void write_scalar(tf::EventsWriter * const events_writer,
    const std::chrono::system_clock::time_point & start_time_point,
    const tf::int64 & step, const std::string & tag, const float & simple_value)
{
    tf::Event event;

    double elapsed_time = std::chrono::duration_cast < std::chrono::seconds > (
        std::chrono::system_clock::now() - start_time_point).count();

    event.set_wall_time(elapsed_time);
    event.set_step(step);

    tf::Summary::Value * summary_val = event.mutable_summary()->add_value();

    summary_val->set_tag(tag);
    summary_val->set_simple_value(simple_value);
    events_writer->WriteEvent(event);
}

int main()
{
    tf::EventsWriter events_writer ("./histogram");

    auto start_time_point = std::chrono::system_clock::now();

    for (int i = 0; i < 150; ++i)
    {
        write_scalar(&events_writer, start_time_point, i, "loss", 150.f / i);
    }

    return 0;
}

以下是我使用的Makefile

CC := g++

LIBRARY_PATH := /usr/local/lib/python2.7/dist-packages/tensorflow

CCFLAGS := -std=c++11 -O3 -fPIC -Wall

INCLUDES := -isystem /usr/local/lib/python2.7/dist-packages/tensorflow/include
LIBRARIES := $(addprefix -L,$(LIBRARY_PATH)) \
-l:libtensorflow_framework.so -l:libprotobuf.so

BIN := ./bin/histogram
SRC := $(wildcard ./src/*)

all: $(BIN)

./bin/%: ./.obj/%.o
    @mkdir -p ./bin
    $(CC) $< $(LIBRARIES) -o $@

./.obj/%.o: ./src/%.cpp
    @mkdir -p ./.obj
    $(CC) -c $< $(CCFLAGS) $(INCLUDES) -o $@

.PHONY: clean
clean:
    $(RM) -r $(BIN)

但是当我运行命令make all时出现以下错误:

g++ -c src/histogram.cpp -std=c++11 -O3 -fPIC -Wall -isystem /usr/local/lib/python2.7/dist-packages/tensorflow/include -o .obj/histogram.o
g++ .obj/histogram.o -L/usr/local/lib/python2.7/dist-packages/tensorflow -l:libtensorflow_framework.so -l:libprotobuf.so -o bin/histogram
.obj/histogram.o: In function `main':
histogram.cpp:(.text.startup+0x99): undefined reference to `tensorflow::EventsWriter::EventsWriter(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
collect2: error: ld returned 1 exit status
Makefile:17: recipe for target 'bin/histogram' failed
make: *** [bin/histogram] Error 1
rm .obj/histogram.o

似乎gcc无法找到EventsWriter构造函数的定义。我在Google上搜索了此问题,看来根据How I can use fileWrite summary in tensorFlow C++ API to view it in Tensorboard,链接libtensorflow_framework.so可以解决此问题,但是我已经在libtensorflow_framework.so中链接了Makefile。有人可以帮我解决这个问题吗?谢谢。

0 个答案:

没有答案