Tensorflow 张量流结构搜索
我试图实现一种结构搜索机制,找到块并将它们包装在块中 我是机器学习新手,一开始我是从Tensorflow 张量流结构搜索,tensorflow,tensorflow.js,Tensorflow,Tensorflow.js,我试图实现一种结构搜索机制,找到块并将它们包装在块中 我是机器学习新手,一开始我是从brain.js开始的。这个库非常简单明了,我从第一次开始就意识到发生了什么,这个库适合简单的任务 但不幸的是,此库不起作用,前面我问过如何查找块: 我决定尝试tensorflow,但要理解这个库很困难,我仍然不理解它是如何学习的,因为有输入和结果应该是什么 下面是我如何尝试搜索brain.js 列车发电机计算 var trainData=[]; 函数随机整数(最小值、最大值){ var rand=min-0
brain.js
开始的。这个库非常简单明了,我从第一次开始就意识到发生了什么,这个库适合简单的任务
但不幸的是,此库不起作用,前面我问过如何查找块:
我决定尝试tensorflow
,但要理解这个库很困难,我仍然不理解它是如何学习的,因为有输入和结果应该是什么
下面是我如何尝试搜索brain.js
列车发电机计算
var trainData=[];
函数随机整数(最小值、最大值){
var rand=min-0.5+Math.random()*(max-min+1)
//兰德=数学圆(兰德);
返回兰特;
}
函数getRandomColor(){
变量字母='0123456789ABCDEF';
var color='#';
对于(变量i=0;i<6;i++){
颜色+=字母[Math.floor(Math.random()*16)];
}
返回颜色;
}
var Generate=新函数(){
var canvas=document.getElementById('generate');
var ctx=canvas.getContext('2d');
变量元素={
输入:[],
输出:[]
}
变量大小={
宽度:240,
身高:140
}
画布宽度=500;
canvas.height=250;
this.next=函数(){
this.build();
列车数据推送({
输入:元素输入,
输出:元素输出
});
}
this.clear=函数(){
clearRect(0,0,canvas.width,canvas.height);
}
this.draw=函数(){
这个.clear();
本项目(要素输入、功能(项目){
ctx.strokeStyle=“绿色”;
ctx.strokeRect(第[0]项、第[1]项、第[2]项、第[3]项);
})
本项目(要素输出、功能(项目){
ctx.strokeStyle=“蓝色”;
ctx.strokeRect(第[0]项、第[1]项、第[2]项、第[3]项);
})
}
this.item=函数(其中,调用){
对于(变量i=0;i
我的目标是训练网络找到元素并显示它们的大小
程序:点击培训点击生成点击计算
蓝色方块包裹绿色方块,这应该是结果,红色方块表示它已找到
<html>
<head>
<script src="https://cdn.rawgit.com/BrainJS/brain.js/5797b875/browser.js"></script>
</head>
<body>
<div>
<button onclick="train()">train</button><button onclick="Generate.next(); Generate.draw();">generate</button><button onclick="calculate()">calculate</button>
</div>
<canvas id="generate" style="border: 1px solid #000"></canvas>
</body>
<script type="text/javascript">
var trainData = [];
function randomInteger(min, max) {
var rand = min - 0.5 + Math.random() * (max - min + 1)
//rand = Math.round(rand);
return rand;
}
function getRandomColor() {
var letters = '0123456789ABCDEF';
var color = '#';
for (var i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}
var Generate = new function(){
var canvas = document.getElementById('generate');
var ctx = canvas.getContext('2d');
var elem = {
input: [],
output: []
}
var size = {
width: 240,
height: 140
}
canvas.width = 500;
canvas.height = 250;
this.next = function(){
this.build();
trainData.push({
input: elem.input,
output: elem.output
});
}
this.clear = function(){
ctx.clearRect(0, 0, canvas.width, canvas.height);
}
this.draw = function(){
this.clear();
this.item(elem.input, function(item){
ctx.strokeStyle = "green";
ctx.strokeRect(item[0], item[1], item[2], item[3]);
})
this.item(elem.output, function(item){
ctx.strokeStyle = "blue";
ctx.strokeRect(item[0], item[1], item[2], item[3]);
})
}
this.item = function(where, call){
for (var i = 0; i < where.length; i+=4) {
var input = [
where[i],
where[i+1],
where[i+2],
where[i+3],
];
this.denormalize(input);
call(input)
}
}
this.normalize = function(input){
input[0] = input[0] / 500;
input[1] = input[1] / 250;
input[2] = input[2] / 500;
input[3] = input[3] / 250;
}
this.denormalize = function(input){
input[0] = input[0] * 500;
input[1] = input[1] * 250;
input[2] = input[2] * 500;
input[3] = input[3] * 250;
}
this.empty = function(add){
var data = [];
for (var i = 0; i < add; i++) {
data = data.concat([0,0,0,0]);
}
return data;
}
this.build = function(){
var output = [];
var input = [];
size.width = randomInteger(100,500);
size.height = randomInteger(50,250);
var lines = 1;//Math.round(size.height / 100);
var line_size = 0;
var line_offset = 0;
for(var i = 0; i < lines; i++){
line_size = randomInteger(30,Math.round(size.height / lines));
var columns = Math.round(randomInteger(1,3));
var columns_width = 0;
var columns_offset = 0;
for(var c = 0; c < columns; c++){
columns_width = randomInteger(30,Math.round(size.width / columns));
var item = [
columns_offset + 10,
line_offset + 10,
columns_width - 20,
line_size - 20
];
this.normalize(item);
input = input.concat(item);
columns_offset += columns_width;
}
var box = [
0,
line_offset,
columns_offset,
line_size
]
this.normalize(box);
output = output.concat(box);
line_offset += line_size + 10;
}
elem.input = input.concat(this.empty(5 - Math.round(input.length / 4)));
elem.output = output.concat(this.empty(2 - Math.round(output.length / 4)));
}
this.get = function(){
return elem.input;
}
this.calculate = function(result, stat){
console.log('brain:',result);
this.item(result, function(item){
ctx.strokeStyle = "red";
ctx.strokeRect(item[0], item[1], item[2], item[3]);
})
}
this.train = function(){
for(var i = 0; i < 1400; i++){
this.next();
}
}
}
Generate.train();
Generate.log = true;
var net,stat;
function train(){
net = new brain.NeuralNetwork({ hiddenLayers: [4],activation: 'tanh'});
stat = net.train(trainData,{log: true, iterations: 1250,learningRate: 0.0001,errorThresh:0.0005});
console.log('stat:',stat)
}
function calculate(){
Generate.calculate(net.run(Generate.get()))
}
</script>
</html>
features = [[[1, 2, 3, 4], [2, 4, 5, 6], [3, 4, 2, 2]]]
labels = [[1, 2, 7, 10]]