return()
endif(NOT CaffeProto_FOUND)
+nncc_find_package(Caffe QUIET)
+
+if(NOT Caffe_FOUND)
+ return()
+endif(NOT Caffe_FOUND)
+
file(GLOB_RECURSE SOURCES "src/*.cpp")
add_executable(caffegen ${SOURCES})
target_link_libraries(caffegen nncc_foundation)
target_link_libraries(caffegen cli)
target_link_libraries(caffegen caffeproto)
+target_link_libraries(caffegen caffe)
+#include "InitCommand.h"
#include "FillCommand.h"
#include "EncodeCommand.h"
#include "DecodeCommand.h"
{
cli::App app{argv[0]};
+ app.insert("init", nncc::foundation::make_unique<InitCommand>());
app.insert("fill", nncc::foundation::make_unique<FillCommand>());
app.insert("encode", nncc::foundation::make_unique<EncodeCommand>());
app.insert("decode", nncc::foundation::make_unique<DecodeCommand>());
--- /dev/null
+#include "InitCommand.h"
+
+#include <caffe/net.hpp>
+#include <caffe/util/upgrade_proto.hpp>
+#include <caffe/proto/caffe.pb.h>
+
+#include <google/protobuf/io/coded_stream.h>
+#include <google/protobuf/io/zero_copy_stream_impl.h>
+#include <google/protobuf/text_format.h>
+
+#include <iostream>
+
+int InitCommand::run(int, const char * const *) const
+{
+ // Read prototxt from standard input
+ ::caffe::NetParameter in;
+ {
+ google::protobuf::io::FileInputStream is{0};
+ if (!google::protobuf::TextFormat::Parse(&is, &in))
+ {
+ std::cerr << "ERROR: Failed to parse prototxt" << std::endl;
+ return 255;
+ }
+ }
+
+ // Upgrade prototxt if necessary
+ if (::caffe::NetNeedsUpgrade(in))
+ {
+ if (!::caffe::UpgradeNetAsNeeded("<stdin>", &in))
+ {
+ std::cerr << "ERROR: Failed to upgrade prototxt" << std::endl;
+ return 255;
+ }
+ }
+
+ ::caffe::Net<float> net(in);
+
+ // Extract initialized parameters
+ ::caffe::NetParameter out;
+ {
+ net.ToProto(&out);
+ }
+
+ // Write initialized parameters to standard output
+ google::protobuf::io::FileOutputStream os(1);
+ google::protobuf::TextFormat::Print(out, &os);
+
+ return 0;
+}
--- /dev/null
+#ifndef __INIT_COMMAND_H__
+#define __INIT_COMMAND_H__
+
+#include <cli/Command.h>
+
+struct InitCommand final : public cli::Command
+{
+ int run(int argc, const char * const *argv) const override;
+};
+
+#endif // __INIT_COMMAND_H__