提交 7f500f45 编写于 作者: S superjom

fix image

just a trick to store int8 in protobuf

should limit the maximum image shape latter
上级 5045c93a
......@@ -65,22 +65,23 @@ def get_image_tags(storage, mode):
def get_image_tag_steps(storage, mode, tag):
# remove suffix '/x'
res = re.search(r".*/([0-9]+$)", tag)
step_index = 0
sample_index = 0
origin_tag = tag
if res:
tag = tag[:tag.rfind('/')]
step_index = int(res.groups()[0])
sample_index = int(res.groups()[0])
reader = storage.as_mode(mode)
image = reader.image(tag)
res = []
for i in range(image.num_samples()):
record = image.record(step_index, i)
for step_index in range(image.num_records()):
record = image.record(step_index, sample_index)
shape = record.shape()
query = urllib.urlencode({
'sample': 0,
'index': i,
'index': step_index,
'tag': origin_tag,
'run': mode,
})
......
......@@ -5,4 +5,4 @@ export PYTHONPATH="$(pwd)/..:/home/superjom/project/VisualDL/build/visualdl/logi
export FLASK_APP=visual_dl.py
export FLASK_DEBUG=1
python visual_dl.py --logdir ./tmp/mock --host 172.23.233.68 --port 8041
python visual_dl.py --logdir ./tmp/mock --host 172.23.233.68 --port 8043
......@@ -29,14 +29,15 @@ for i in range(100):
def add_image(mode):
writer_ = writer.as_mode(mode)
tag = "layer1/layer2/image0"
image_writer = writer_.image(tag, 10, 1)
num_passes = 25
num_samples = 100
shape = [10, 10, 3]
# TODO check step_cycle
num_samples = 10
num_passes = 10
image_writer = writer_.image(tag, num_samples, 1)
shape = [400, 400, 3]
for pass_ in xrange(num_passes):
image_writer.start_sampling()
for ins in xrange(num_samples):
for ins in xrange(2*num_samples):
index = image_writer.is_sample_taken()
if index != -1:
data = np.random.random(shape) * 256
......
......@@ -135,6 +135,7 @@ def images():
tag = request.args.get('displayName')
result = lib.get_image_tag_steps(storage, mode, tag)
result = gen_result(0, "", result)
return Response(json.dumps(result), mimetype='application/json')
......@@ -143,10 +144,10 @@ def images():
def individual_image():
mode = request.args.get('run')
tag = request.args.get('tag') # include a index
step_index = request.args.get('index') # index of step
step_index = int(request.args.get('index')) # index of step
offset = 0
imagefile = lib.get_invididual_image(storage, mode, tag, step_)
imagefile = lib.get_invididual_image(storage, mode, tag, step_index)
response = send_file(
imagefile, as_attachment=True, attachment_filename='img.png')
return response
......
......@@ -37,6 +37,7 @@ template class SimpleWriteSyncGuard<Entry<double>>;
template class SimpleWriteSyncGuard<Entry<bool>>;
template class SimpleWriteSyncGuard<Entry<long>>;
template class SimpleWriteSyncGuard<Entry<std::string>>;
template class SimpleWriteSyncGuard<Entry<std::vector<char>>>;
template class SimpleWriteSyncGuard<Entry<int>>;
} // namespace visualdl
......@@ -108,8 +108,13 @@ void Image::SetSample(int index,
CHECK_LE(index, num_records_);
// set data
auto entry = step_.MutableData<value_t>(index);
entry.SetMulti(data);
auto entry = step_.MutableData<std::vector<char>>(index);
// trick to store int8 to protobuf
std::vector<char> data_str(data.size());
for (int i = 0; i < data.size(); i++) {
data_str[i] = data[i];
}
entry.Set(data_str);
static_assert(
!is_same_type<value_t, shape_t>::value,
......@@ -135,10 +140,13 @@ std::string ImageReader::caption() {
ImageReader::ImageRecord ImageReader::record(int offset, int index) {
ImageRecord res;
auto record = reader_.record(offset);
auto data_entry = record.data<value_t>(index);
auto data_entry = record.data<std::vector<char>>(index);
auto shape_entry = record.data<shape_t>(index);
res.data = data_entry.GetMulti();
auto data_str = data_entry.Get();
std::transform(data_str.begin(),
data_str.end(),
std::back_inserter(res.data),
[](char i) { return (int)((unsigned char)i); });
res.shape = shape_entry.GetMulti();
res.step_id = record.id();
return res;
......
......@@ -210,7 +210,7 @@ struct ImageReader {
struct ImageRecord {
int step_id;
std::vector<value_t> data;
std::vector<int> data;
std::vector<shape_t> shape;
};
......
......@@ -21,7 +21,22 @@ namespace visualdl {
WRITE_GUARD \
}
template <>
void Entry<std::vector<char>>::Set(std::vector<char> v) {
entry->set_dtype(storage::DataType::kBytes);
entry->set_y(std::string(v.begin(), v.end()));
WRITE_GUARD
}
template <>
void Entry<std::vector<char>>::Add(std::vector<char> v) {
entry->set_dtype(storage::DataType::kBytess);
*entry->add_ys() = std::string(v.begin(), v.end());
WRITE_GUARD
}
IMPL_ENTRY_SET_OR_ADD(Set, int, kInt32, set_i32);
IMPL_ENTRY_SET_OR_ADD(Set, std::string, kString, set_s);
IMPL_ENTRY_SET_OR_ADD(Set, int64_t, kInt64, set_i64);
IMPL_ENTRY_SET_OR_ADD(Set, bool, kBool, set_b);
IMPL_ENTRY_SET_OR_ADD(Set, float, kFloat, set_f);
......@@ -42,7 +57,7 @@ IMPL_ENTRY_SETMUL(bool, kBool, bs);
#define IMPL_ENTRY_GET(T, fieldname__) \
template <> \
T EntryReader<T>::Get() const { \
data_.fieldname__(); \
return data_.fieldname__(); \
}
IMPL_ENTRY_GET(int, i32);
......@@ -52,6 +67,12 @@ IMPL_ENTRY_GET(double, d);
IMPL_ENTRY_GET(std::string, s);
IMPL_ENTRY_GET(bool, b);
template <>
std::vector<char> EntryReader<std::vector<char>>::Get() const {
const auto& y = data_.y();
return std::vector<char>(y.begin(), y.end());
}
#define IMPL_ENTRY_GET_MULTI(T, fieldname__) \
template <> \
std::vector<T> EntryReader<T>::GetMulti() const { \
......@@ -70,10 +91,12 @@ template class Entry<int>;
template class Entry<float>;
template class Entry<double>;
template class Entry<bool>;
template class Entry<std::vector<char>>;
template class EntryReader<int>;
template class EntryReader<float>;
template class EntryReader<double>;
template class EntryReader<bool>;
template class EntryReader<std::vector<char>>;
} // namespace visualdl
......@@ -9,15 +9,16 @@ enum DataType {
kDouble = 3;
kString = 4;
kBool = 5;
kBytes = 6;
// entrys
kInt64s = 6;
kFloats = 7;
kDoubles = 8;
kStrings = 9;
kInt32s = 10;
kBools = 11;
kUnknown = 12;
kInt64s = 7;
kFloats = 8;
kDoubles = 9;
kStrings = 10;
kInt32s = 11;
kBools = 12;
kBytess = 13;
kUnknown = 14;
}
// A data array, which type is `type`.
......@@ -29,16 +30,18 @@ message Entry {
int32 i32 = 2;
int64 i64 = 3;
string s = 4;
float f = 5;
double d = 6;
bool b = 7;
bytes y = 5;
float f = 6;
double d = 7;
bool b = 8;
// array
repeated int64 i64s = 8;
repeated float fs = 9;
repeated double ds = 10;
repeated int32 i32s = 11;
repeated string ss = 12;
repeated bool bs = 13;
repeated int64 i64s = 9;
repeated float fs = 10;
repeated double ds = 11;
repeated int32 i32s = 12;
repeated string ss = 13;
repeated bool bs = 14;
repeated bytes ys = 15;
}
/*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册