refactor: 改为 Wasserstein GAN

This commit is contained in:
AncTe committed 2025-04-06 18:44:18 +08:00
1 parent d7209a68a2
commit 29cfb4d029
14 files changed
+643 -183

No files matched your search

+8 -16
View File
@@ -4,7 +4,7 @@ import { MinamoTrainData } from './types';
import { generateTrainData } from './process/minamo';
const SOCKET_FILE = '../tmp/ginka_uds';
const [refer] = process.argv.slice(2);
const [refer, replayPath = '../datasets/replay.bin'] = process.argv.slice(2);
let id = 0;
@@ -43,7 +43,7 @@ function generateGANData(
const size2: [number, number] = [map[0].length, map.length];
if (size1[0] !== size2[0] || size1[1] !== size2[1]) return [];
return generateTrainData(v, id2, floor.map, map, size1);
return generateTrainData(v, id2, floor.map, map, size1, false, false, false);
});
return data.flat();
}
@@ -104,7 +104,7 @@ class DataReceiver {
console.log(`UDS IPC connected successfully.`);
});
client.on('data', buffer => {
client.on('data', async buffer => {
const data = DataReceiver.check(buffer);
if (!data) return;
@@ -112,20 +112,19 @@ class DataReceiver {
const simData = map.map(v => generateGANData(keys, referTower, v));
const rc = 0;
const compareData = simData.flat();
const reviewData: MinamoTrainData[] = [];
// 数据通讯 node 输出协议,单位字节:
// 2 - Tensor count; 2 - Review count. Review is right behind train data;
// 2 - Tensor count; 2 - Replay count. Replay is right behind train data;
// 1*tc - Compare count for every map tensor delivered.
// 2*4*(N+rc) - Vision similarity and topo similarity, like vis, topo, vis, topo;
// N*1*H*W - Compare map for every map tensor. rc*2*H*W - Review map tensor.
// N*1*H*W - Compare map for every map tensor. rc*2*H*W - Replay map tensor.
const toSend = Buffer.alloc(
2 + // Tensor count
2 + // Review count
2 + // Replay count
1 * count + // Compare count
2 * 4 * (compareData.length + rc) + // Similarity data
compareData.length * 1 * h * w + // Compare map
rc * 2 * h * w, // Review map
rc * 2 * h * w, // Replay map
0
);
console.log(
@@ -141,7 +140,7 @@ class DataReceiver {
let offset = 0;
toSend.writeInt16BE(count); // Tensor count
toSend.writeInt16BE(0, 2); // Review count
toSend.writeInt16BE(0, 2); // Replay count
offset += 2 + 2;
// Compare count
toSend.set(
@@ -164,13 +163,6 @@ class DataReceiver {
offset // Set from Compare map
);
offset += compareData.length * 1 * h * w;
if (reviewData.length > 0) {
// Review map
toSend.set(
new Uint8Array(reviewData.map(v => [v.map1, v.map2]).flat(4)),
offset // Set from last chunk
);
}
client.write(toSend);
});
+43 -32
View File
@@ -192,7 +192,10 @@ export function generateTrainData(
id2: string,
map1: number[][],
map2: number[][],
size: [number, number]
size: [number, number],
hasSelf: boolean = true,
hasTransform: boolean = true,
hasSimilar: boolean = true
) {
const topoSimilarity = compareMap(id1, id2, map1, map2);
const visionSimilarity = calculateVisualSimilarity(map1, map2);
@@ -205,39 +208,47 @@ export function generateTrainData(
};
const data: MinamoTrainData[] = [];
data.push(train);
// 自身与自身对比的训练集,保证模型对相同地图输出 1
const self1 = `${id1}:${id1}`;
const self2 = `${id2}:${id2}`;
const selfTrain = chooseFrom([self1, self2], Math.floor(Math.random() * 1));
if (selfTrain.includes(self1)) {
const selfTrain1: MinamoTrainData = {
map1: map1,
map2: map1,
topoSimilarity: 1,
visionSimilarity: 1,
size: size
};
data.push(selfTrain1);
if (hasSelf) {
// 自身与自身对比的训练集,保证模型对相同地图输出 1
const self1 = `${id1}:${id1}`;
const self2 = `${id2}:${id2}`;
const selfTrain = chooseFrom([self1, self2], Math.floor(Math.random() * 1));
if (selfTrain.includes(self1)) {
const selfTrain1: MinamoTrainData = {
map1: map1,
map2: map1,
topoSimilarity: 1,
visionSimilarity: 1,
size: size
};
data.push(selfTrain1);
}
if (selfTrain.includes(self2)) {
const selfTrain2: MinamoTrainData = {
map1: map2,
map2: map2,
topoSimilarity: 1,
visionSimilarity: 1,
size: size
};
data.push(selfTrain2);
}
}
if (selfTrain.includes(self2)) {
const selfTrain2: MinamoTrainData = {
map1: map2,
map2: map2,
topoSimilarity: 1,
visionSimilarity: 1,
size: size
};
data.push(selfTrain2);
if (hasTransform) {
const transform = generateTransformData(
id1,
id2,
map1,
map2,
topoSimilarity
);
data.push(...transform.map(v => v[1]))
}
const transform = generateTransformData(
id1,
id2,
map1,
map2,
topoSimilarity
);
const similar = generateSimilarData(id1, map1);
return [...data, ...transform.map(v => v[1]), ...similar.map(v => v[1])];
if (hasSimilar) {
const similar = generateSimilarData(id1, map1);
data.push(...similar.map(v => v[1]))
}
return data;
}
export function generatePair(
+1 -2
View File
@@ -87,8 +87,7 @@ function weisfeilerLehmanIteration(
});
weight *= decay;
});
// 把每个节点的原始标签也加上,权重使用最远权重再衰减1次,可以认为是资源重复率
weight *= decay;
// 把每个节点的原始标签也加上,权重使用最远权重,可以认为是资源重复率
nodes.forEach(node => {
if (!numMap.has(node.originalLabel)) {
numMap.set(node.originalLabel, weight);