我该怎么做.我有一个黑白图像(100x100px):

我应该用这个图像训练一个反向传播神经网络.输入是图像的x,y坐标(从0到99),输出为1(白色)或0(黑色).
一旦网络学会了,我希望它能够根据其权重重现图像,并获得与原始图像最接近的图像.
这是我的backprop实现:
import os
import math
import Image
import random
from random import sample
#------------------------------ class definitions
class Weight:
def __init__(self, fromNeuron, toNeuron):
self.value = random.uniform(-0.5, 0.5)
self.fromNeuron = fromNeuron
self.toNeuron = toNeuron
fromNeuron.outputWeights.append(self)
toNeuron.inputWeights.append(self)
self.delta = 0.0 # delta value, this will accumulate and after each training cycle used to adjust the weight value
def calculateDelta(self, network):
self.delta += self.fromNeuron.value * self.toNeuron.error
class Neuron:
def __init__(self):
self.value = 0.0 # the output
self.idealValue = 0.0 …Run Code Online (Sandbox Code Playgroud) python matlab artificial-intelligence machine-learning neural-network
当我使用此方法调整位图的大小时:
private Bitmap ResizeBitmap(Bitmap b, int nWidth, int nHeight)
{
Bitmap result = new Bitmap(nWidth, nHeight);
using (Graphics g = Graphics.FromImage((Image)result))
{
g.SmoothingMode = SmoothingMode.None;
g.DrawImage(b, 0, 0, nWidth, nHeight);
}
return result;
}
Run Code Online (Sandbox Code Playgroud)
它仍然使用抗锯齿,即使我指定:
g.SmoothingMode = SmoothingMode.None;
Run Code Online (Sandbox Code Playgroud)
我想要一个基本的大小调整,没有任何平滑.
所以我根据这个答案用py2exe编译了一个python脚本.编译过程中没有错误,一切都很顺利.
当我从这样的cmd运行脚本时:
C:\Users\Richard\Dist\backprop3.exe 60
Run Code Online (Sandbox Code Playgroud)
这是我得到的输出:
C:\Users\Richard>C:\Users\Richard\Dist\backprop3.exe 60
Traceback (most recent call last):
File "backprop3.py", line 209, in <module>
File "backprop3.py", line 175, in demo
NameError: global name '__file__' is not defined
C:\Users\Richard>
Run Code Online (Sandbox Code Playgroud)
这是指这一行:
image = Image.open( os.path.dirname( os.path.abspath( __file__ ) )+"/backprop-input.bmp" )
Run Code Online (Sandbox Code Playgroud)
该行只是从当前目录加载图像.问题出在哪儿?
出于某种原因,下面的代码不起作用.我有两个非常相似但不相同的640*480图像(至少几百/千像素应该是不同的).
这就是我比较它们和计算不同像素的方式:
unsigned char* row;
unsigned char* row2;
int count = 0;
// this happens in a loop
// fIplImageHeader is current image
// lastFIplImageHeader is image from previous iteration
if ( NULL != lastFIplImageHeader->imageData ) {
for( int y = 0; y < fIplImageHeader->height; y++ )
{
row = &CV_IMAGE_ELEM( fIplImageHeader, unsigned char, y, 0 );
row2 = &CV_IMAGE_ELEM( lastFIplImageHeader, unsigned char, y, 0 );
for( int x = 0; x < fIplImageHeader->width*fIplImageHeader->nChannels; x += fIplImageHeader->nChannels )
{
if(row[x] …Run Code Online (Sandbox Code Playgroud) 我有一个3200值的数组.用户选择一个数字(比方说50).我想将大数组分成较小的数组,每个数组包含50个值(最后一个包含余数).
你会怎么做?
<?php
abstract class AbstractClass
{
public function __get($theName)
{
return (isset($this->$theName)) ? $this->$theName : NULL;
}
public function __set($theName, $theValue)
{
if (false === property_exists(get_class(), $theName)) {
throw new Exception(get_class()." does not have '".$theName."' property.");
} else {
$this->$theName = $theValue;
}
}
}
class ConcreteClass extends AbstractClass
{
private $x;
private $y;
public function __construct($theX, $theY)
{
$this->x = $theX;
$this->y = $theY;
}
}
$concreteClass = new ConcreteClass(10, 20);
var_dump( $concreteClass->x );
Run Code Online (Sandbox Code Playgroud)
有没有办法让这项工作或我必须将这些魔术方法添加到扩展类?
我知道当我将CURLOPT_FOLLOWLOCATION设置为true时,cURL将跟随Location标头并重定向到新页面.但是有可能只获得新页面的标题而不实际重定向吗?还是不可能?
我刚刚在HTML 5中重写了我的个人简历网页,我喜欢标记头部的更简单,不那么神秘的语法.
但除此之外,HTML 5优于旧版HTML 4.01有什么优势?据我所知,旧版浏览器(Internet Explorer早于9版)不支持HTML 5,并且由于许多人仍然使用这些浏览器,我仍然需要使用Flash变通方法来处理视频标记或类似的HTML 5功能.看起来就像使用HTML 4.01更多的工作.
假设这是我想要分配给BOOL变量的JSON中的值:
"retweeted": false
Run Code Online (Sandbox Code Playgroud)
以下是我解析JSON数据的方法:
NSError *error;
NSArray *timeline = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];
Run Code Online (Sandbox Code Playgroud)
现在,我有一个bool属性定义为:
BOOL *retweeted;
Run Code Online (Sandbox Code Playgroud)
在我的课堂里.当我在解析JSON时这样做:
tweet.retweeted = [[[timeline objectAtIndex:i] objectForKey:@"retweeted"] boolValue];
Run Code Online (Sandbox Code Playgroud)
我收到此错误:

如何解决这个问题呢?
更新:
好的,我设法记录了异常:
[<TweetDetailViewController 0x685f9f0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key toolbar.
Run Code Online (Sandbox Code Playgroud)
我在目标控制器视图中有一个工具栏.这会导致问题吗?
我不知道到底发生了什么事.我根本没有改变segues,他们几分钟前就完美地工作了.我在详细视图控制器中更改了一些不相关的东西,现在应用程序在从根到视图控制器的segue期间崩溃.
我正在尝试调试这个.这是代码崩溃的地方:

跳过:

跳过:

跳过:

好的,这是在prepareForSegue中调用的setter方法:
- (void)setTweet:(Tweet *)newTweet
{
if (_tweet != newTweet) {
_tweet = newTweet;
}
}
Run Code Online (Sandbox Code Playgroud)
我在进入细节控制器时调用配置方法:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self configureView];
}
- (void)configureView
{
// Update the user interface for the tweet detail page
if (_tweet) {
self.tweetUserName.text = _tweet.userName;
self.tweetCreatedAt.text = _tweet.createdAt;
self.tweetText.contentInset = UIEdgeInsetsMake(-4,-8,0,0);
self.tweetText.text = _tweet.text;
if (_tweet.retweeted == YES) {
[self.retweetButton …Run Code Online (Sandbox Code Playgroud)