未验证 提交 c1c2232c 编写于 作者: J Jeff Wang 提交者: GitHub

Update embedding tag (#422)

* Limit embedding tag name to be embedding only

* display the runs to the user, so they can pick which embedding to see

* The server now loads run parameter.

* Remove the need of passing a tag name to embedding log writer and reader.

* Remove un-needed fetch

* Use first item in the list

* rename showingRun to selectedRun
上级 b6f992c0
......@@ -12,6 +12,7 @@
<div class="visual-dl-page-right">
<div class="visual-dl-page-config-container">
<ui-config
:runs-items="runsItems"
:config="config"
/>
</div>
......@@ -20,7 +21,7 @@
</template>
<script>
import {getHighDimensionalDatasets} from '../service';
import {getHighDimensionalDatasets, getRuns} from '../service';
import autoAdjustHeight from '../common/util/autoAdjustHeight';
import Config from './ui/Config';
import Chart from './ui/Chart';
......@@ -33,18 +34,27 @@ export default {
name: 'HighDimensional',
data() {
return {
runsArray: [],
config: {
searchText: '',
displayWordLabel: true,
dimension: '2',
reduction: 'tsne',
selectedRun: '',
running: true,
},
embeddingData: [],
};
},
created() {
this.fetchDatasets();
getRuns().then(({errno, data}) => {
this.runsArray = data;
// Setting selectedRun should trigger fetchDatasets
if (data.length > 0) {
this.config.selectedRun = data[0];
}
});
},
watch: {
'config.dimension': function(val) {
......@@ -53,16 +63,31 @@ export default {
'config.reduction': function(val) {
this.fetchDatasets();
},
'config.selectedRun': function(val) {
this.fetchDatasets();
},
},
mounted() {
autoAdjustHeight();
},
computed: {
runsItems() {
let runsArray = this.runsArray || [];
return runsArray.map((item) => {
return {
name: item,
value: item,
};
});
},
},
methods: {
fetchDatasets() {
// Fetch the data from the server. Passing dimension and reduction method
let params = {
dimension: this.config.dimension,
reduction: this.config.reduction,
run: this.config.selectedRun,
};
getHighDimensionalDatasets(params).then(({errno, data}) => {
let vectorData = data.embedding;
......
......@@ -39,6 +39,17 @@
value="pca"/>
</v-radio-group>
<v-radio-group
label="Run"
v-model="config.selectedRun"
dark>
<v-radio
v-for="item in runsItems"
:key="item.name"
:label="item.name"
:value="item.value" />
</v-radio-group>
<v-btn
:color="config.running ? 'primary' : 'error'"
v-model="config.running"
......@@ -55,6 +66,10 @@
export default {
props: {
runsItems: {
type: Array,
required: true,
},
config: {
type: Object,
required: true,
......
......@@ -18,10 +18,12 @@ from __future__ import absolute_import
from visualdl import core
dtypes = ("float", "double", "int32", "int64")
EMBEDDING_TAG = 'embedding'
def check_tag_name_valid(tag):
assert '%' not in tag, "character % is a reserved word, it is not allowed in tag."
assert tag != EMBEDDING_TAG, "embedding is a reserved word, it is not allowed in tag."
def check_mode_name_valid(tag):
......@@ -140,9 +142,8 @@ class LogReader(object):
check_tag_name_valid(tag)
return self.reader.get_text(tag)
def embedding(self, tag):
check_tag_name_valid(tag)
return self.reader.get_embedding(tag)
def embedding(self):
return self.reader.get_embedding(EMBEDDING_TAG)
def audio(self, tag):
"""
......@@ -290,9 +291,8 @@ class LogWriter(object):
check_tag_name_valid(tag)
return self.writer.new_text(tag)
def embedding(self, tag):
check_tag_name_valid(tag)
return self.writer.new_embedding(tag)
def embedding(self):
return self.writer.new_embedding(EMBEDDING_TAG)
def save(self):
self.writer.save()
......
......@@ -303,14 +303,9 @@ def get_texts(storage, mode, tag, num_records=100):
return res
def get_embeddings(storage,
mode,
tag,
reduction,
dimension=2,
num_records=5000):
def get_embeddings(storage, mode, reduction, dimension=2, num_records=5000):
with storage.mode(mode) as reader:
embedding = reader.embedding(tag)
embedding = reader.embedding()
labels = embedding.get_all_labels()
high_dimensional_vectors = embedding.get_all_embeddings()
......
......@@ -261,10 +261,11 @@ def texts():
@app.route('/data/plugin/embeddings/embeddings')
def embeddings():
run = request.args.get('run')
dimension = request.args.get('dimension')
reduction = request.args.get('reduction')
key = os.path.join('/data/plugin/embeddings/embeddings', dimension, reduction)
data = cache_get(key, try_call, lib.get_embeddings, log_reader, 'train', 'scratch/embedding', reduction, int(dimension))
key = os.path.join('/data/plugin/embeddings/embeddings', run, dimension, reduction)
data = cache_get(key, try_call, lib.get_embeddings, log_reader, run, reduction, int(dimension))
result = gen_result(0, "", data)
return Response(json.dumps(result), mimetype='application/json')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册