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