小编NEW*_*SER的帖子

TensorFlow:在变量初始化中"尝试使用未初始化的值"

我试图使用TensorFlow在Python中实现多元线性回归,但遇到了一些逻辑和实现问题.我的代码抛出以下错误:

Attempting to use uninitialized value Variable
Caused by op u'Variable/read'
Run Code Online (Sandbox Code Playgroud)

理想情况下,weights输出应该是[2, 3]

def hypothesis_function(input_2d_matrix_trainingexamples,
                        output_matrix_of_trainingexamples,
                        initial_parameters_of_hypothesis_function,
                        learning_rate, num_steps):
    # calculate num attributes and num examples
    number_of_attributes = len(input_2d_matrix_trainingexamples[0])
    number_of_trainingexamples = len(input_2d_matrix_trainingexamples)

    #Graph inputs
    x = []
    for i in range(0, number_of_attributes, 1):
        x.append(tf.placeholder("float"))
    y_input = tf.placeholder("float")

    # Create Model and Set Model weights
    parameters = []
    for i in range(0, number_of_attributes, 1):
        parameters.append(
            tf.Variable(initial_parameters_of_hypothesis_function[i]))

    #Contruct linear model
    y = tf.Variable(parameters[0], "float")
    for i in range(1, number_of_attributes, …
Run Code Online (Sandbox Code Playgroud)

python machine-learning linear-regression tensorflow

43
推荐指数
4
解决办法
9万
查看次数

如何在张量流中实现多元线性随机梯度下降算法?

我从简单实现单变量线性梯度下降开始,但不知道将其扩展到多变量随机梯度下降算法?

单变量线性回归

import tensorflow as tf
import numpy as np

# create random data
x_data = np.random.rand(100).astype(np.float32)
y_data = x_data * 0.5

# Find values for W that compute y_data = W * x_data 
W = tf.Variable(tf.random_uniform([1], -1.0, 1.0))
y = W * x_data

# Minimize the mean squared errors.
loss = tf.reduce_mean(tf.square(y - y_data))
optimizer = tf.train.GradientDescentOptimizer(0.01)
train = optimizer.minimize(loss)

# Before starting, initialize the variables
init = tf.initialize_all_variables()

# Launch the graph.
sess = tf.Session()
sess.run(init)

# Fit …
Run Code Online (Sandbox Code Playgroud)

python machine-learning linear-regression tensorflow

6
推荐指数
1
解决办法
6721
查看次数

数不。没有比较的 1 和 0

在只有 1 和 0 的数组中,你怎么算数。1s 和 0s 没有比较,然后将其修改为 3s 和 5s 的数组。
我的方法是使用累积数组,使得cumulative[i]=array[i]+cumulative[i-1]。一个数=累积[n]个零数=n-累积[n];这种方法正确吗?或者建议一些其他的方法?我们可以将它转换为 3 和 5 的数组而不进行比较吗?

arrays algorithm data-structures

5
推荐指数
1
解决办法
941
查看次数

将 RGB 图像转换为 CMY

如何将RGB彩色图像或简单的图像转换为CMY彩色图像并提取每个分量青色(C)洋红色(M)和黄色(Y)?我的方法:-

I=imread('Capture2.PNG'); 
I3 = I;
I2 =I;
I1 = I;

I1(:,:,2:3)=0;
RED = I1;

I2(:,:,1:2) = 0;
BLUE = I2;

I3(:,:,1:3)=0;
GREEN=I3;

tic;
figure;imshow(RED);
figure;imshow(BLUE);
figure;imshow(GREEN);
c = 1.0-RED;
m = 1.0-GREEN;
y = 1.0-BLUE;
figure;imshow(c);
figure;imshow(m);
figure;imshow(y);
Run Code Online (Sandbox Code Playgroud)

matlab image image-processing

2
推荐指数
1
解决办法
9121
查看次数