未验证 提交 42c327c4 编写于 作者: Y Yan Chunwei 提交者: GitHub

enhance/image binary record use sampling (#132)

上级 9867588d
#include "visualdl/logic/sdk.h"
#include <cstdio>
#include "visualdl/logic/histogram.h"
#include "visualdl/storage/binary_record.h"
#include "visualdl/utils/image.h"
#include "visualdl/utils/logging.h"
#include "visualdl/utils/macro.h"
namespace visualdl {
......@@ -202,6 +205,14 @@ void Image::SetSample(int index,
brcd.tofile();
auto entry = step_.MutableData<std::vector<byte_t>>(index);
// update record
auto old_hash = entry.reader().GetRaw();
if (!old_hash.empty()) {
std::string old_path =
GenBinaryRecordDir(step_.parent()->dir()) + "/" + old_hash;
CHECK_EQ(std::remove(old_path.c_str()), 0) << "delete old binary record "
<< old_path << " failed";
}
entry.SetRaw(brcd.hash());
static_assert(
......
......@@ -2,7 +2,7 @@ import pprint
import unittest
import lib
import storage
from visualdl import LogReader, LogWriter
import pprint
from storage_mock import add_scalar, add_image, add_histogram
......@@ -11,7 +11,7 @@ from storage_mock import add_scalar, add_image, add_histogram
class LibTest(unittest.TestCase):
def setUp(self):
dir = "./tmp/mock"
writer = storage.LogWriter(dir, sync_cycle=10)
writer = LogWriter(dir, sync_cycle=10)
add_scalar(writer, "train", "layer/scalar0/min", 1000, 1)
add_scalar(writer, "test", "layer/scalar0/min", 1000, 10)
......@@ -30,7 +30,7 @@ class LibTest(unittest.TestCase):
add_histogram(writer, "train", "layer/histogram0", 100)
add_histogram(writer, "test", "layer/histogram0", 100)
self.reader = storage.LogReader(dir)
self.reader = LogReader(dir)
def test_modes(self):
modes = lib.get_modes(self.reader)
......
......@@ -11,6 +11,21 @@ struct Storage;
using byte_t = unsigned char;
struct EntryReader {
EntryReader(storage::Entry x) : data_(x) {}
// Get a single value.
template <typename T>
T Get() const;
// Get repeated field.
template <typename T>
std::vector<T> GetMulti() const;
std::string GetRaw() { return data_.y(); }
private:
storage::Entry data_;
};
/*
* Utility helper for storage::Entry.
*/
......@@ -44,23 +59,11 @@ struct Entry {
Storage* parent() { return x_; }
void set_parent(Storage* x) { x_ = x; }
private:
Storage* x_;
};
struct EntryReader {
EntryReader(storage::Entry x) : data_(x) {}
// Get a single value.
template <typename T>
T Get() const;
// Get repeated field.
template <typename T>
std::vector<T> GetMulti() const;
std::string GetRaw() { return data_.y(); }
// TODO(ChunweiYan) avoid copy.
EntryReader reader() { return EntryReader(*entry); }
private:
storage::Entry data_;
Storage* x_;
};
} // namespace visualdl
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册