- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在学习 tensorflow 时,我尝试调整基本的 softmax MNIST 示例来处理我自己的图像集。这是建筑物的航拍照片,我想按屋顶类型对它们进行分类。可以进行 4 种这样的分类。
简单(也许是幼稚)的想法是调整图像大小(因为它们并不完全相同)并将其展平。然后更改代码中的张量形状并运行它。当然,尽管如此还是行不通。首先让我向您展示代码。
# Load csv Data
filenames = []
_answers = []
with open('/home/david/DSG/id_train.csv') as csvfile:
csv_reader = csv.reader(csvfile, delimiter=',')
for row in csv_reader:
one_hot_vec = [0, 0, 0, 0]
one_hot_vec[int(row[1])-1] = 1
_answers.append(np.asarray(one_hot_vec))
filenames.append("/home/david/DSG/roof_images/" + str(row[0]) + ".jpg")
sess = tf.InteractiveSession()
# Image Loading and processing
filename_q = tf.train.string_input_producer(filenames)
reader = tf.WholeFileReader()
key, value = reader.read(filename_q)
__img = tf.image.decode_jpeg(value, channels=1)
_img = tf.expand_dims(tf.image.convert_image_dtype(__img, tf.float32),0)
img = tf.image.resize_nearest_neighbor(_img, [150,150])
# Actual model
x = tf.placeholder(tf.float32, [None, 22500])
W = tf.Variable(tf.zeros([22500, 4]))
b = tf.Variable(tf.zeros([4]))
y = tf.nn.softmax(tf.matmul(x, W) + b)
# Training algorithm
y_ = tf.placeholder(tf.float32, [None, 4])
cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(tf.clip_by_value(y,1e-10,1.0)), reduction_indices=[1]))
train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)
# Evaluate model, this checks the results from the y (prediciton matrix) against the known answers (y_)
correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
coord = tf.train.Coordinator()
init_op = tf.initialize_all_variables()
sess.run(init_op)
threads = tf.train.start_queue_runners(sess=sess, coord=coord)
# Loads and process all the images, adding them to an array for later use
images = []
for i in range(8000):
if i % 100 == 0:
print("Processing Images " + str(100*(i+100)/8000) + "% complete")
image = img.eval().flatten()
images.append(image)
# Train our model
for i in range(80):
print("Training the Model " + str(100*(i+1)/80) + "% complete")
batchImages = images[i*100:((i+1)*100)]
batchAnswers = answers[i*100:((i+1)*100)].astype(float)
# Here's a debug line I put in to see what the numbers were
print(sess.run(y, feed_dict={x: batchImages, y_: batchAnswers}))
sess.run(train_step, feed_dict={x: batchImages, y_: batchAnswers})
coord.request_stop()
coord.join(threads)
可以看出,我在进行过程中打印了 softmax 的 y 值。结果是张量看起来像这样 [0., 0., 0., 1.]
。我觉得这很奇怪。所以我打印了 tf.matmul(x, W) + b 的值。
结果是这样的:
[[-236.86216736 -272.89904785 59.67744446 450.08377075]
[-327.19482422 -384.06918335 87.47353363 623.79052734]
[-230.79460144 -264.78787231 60.29759598 435.28485107]
[-188.10324097 -212.30155945 53.8230629 346.58175659]
[-180.26617432 -209.45767212 48.90292358 340.82092285]
[-177.13232422 -200.59474182 45.97179413 331.75531006]
[-225.94104004 -258.97390747 61.54353333 423.37136841]
[-259.33599854 -290.73773193 67.69062042 482.38308716]
[-151.53468323 -174.09906006 39.97481537 285.65893555]
[-237.23356628 -272.71789551 65.12500763 444.82647705]
..... you get the idea
[-195.14971924 -221.30851746 53.09790802 363.36032104]
[-157.30508423 -175.47320557 40.4044342 292.37384033]
[-178.94332886 -203.36262512 47.0838356 335.22219849]
[-180.61688232 -200.0609436 45.12242508 335.55541992]
[-145.7559967 -163.06838989 35.25980377 273.56466675]
[-194.07254028 -213.78709412 53.14990997 354.70977783]
[-191.92044067 -219.13395691 49.84062958 361.21377563]]
对于手动计算 softmax 的第一个、第二个和第三个元素,您会得到 E-200 数量级的数字,基本上为零。然后是第四个元素的大于 1 的数字。由于所有人都遵循这种模式,显然有些事情是错误的。
现在我已经检查了输入,我的答案是一个热向量,如 [0, 1, 0, 0]
并且我的图像被展平,值标准化为 0 和 1 (漂浮)。就像 MNIST 的例子一样。
我还注意到,在 MNIST 示例中,matmul 的值要小得多。属于E0级。这是因为每个图像上有 784 个元素,而不是 22500 个吗?这是问题的原因吗?
哎呀,也许由于某种原因这永远不会起作用。我需要一些帮助。
编辑:我决定检查图像大小是否有任何影响,果然 matmul 确实给出了较小的数字。然而它们仍然表现出一种模式,所以我再次通过 softmax 运行它并得到以下输出:
[[ 2.12474524e-20 1.00000000e+00 1.10456488e-18 0.00000000e+00]
[ 3.22400550e-21 1.00000000e+00 1.24568592e-19 0.00000000e+00]
[ 2.49283055e-28 1.00000000e+00 6.52334536e-26 0.00000000e+00]
[ 4.73190862e-23 1.00000000e+00 3.71980738e-21 0.00000000e+00]
[ 1.11151765e-26 1.00000000e+00 4.14652626e-24 0.00000000e+00]
[ 2.23096276e-22 1.00000000e+00 7.21511359e-21 0.00000000e+00]
[ 1.41888640e-23 1.00000000e+00 2.13637447e-21 0.00000000e+00]
[ 3.55662848e-17 1.00000000e+00 5.14018079e-16 4.06785808e-33]
[ 8.25783417e-26 1.00000000e+00 2.95267040e-23 0.00000000e+00]
[ 1.09395607e-25 1.00000000e+00 3.76775998e-23 0.00000000e+00]
[ 9.34879669e-13 1.00000000e+00 1.07488766e-11 7.21446627e-25]
[ 3.09687017e-34 1.00000000e+00 5.22547065e-31 0.00000000e+00]
[ 2.10362117e-22 1.00000000e+00 1.31067148e-20 0.00000000e+00]
[ 5.86830220e-23 1.00000000e+00 9.55902033e-21 0.00000000e+00]
[ 9.59656235e-17 1.00000000e+00 2.98987045e-15 7.10348533e-32]
[ 2.33712669e-16 1.00000000e+00 3.26934410e-15 1.55066807e-31]
[ 1.09302052e-27 1.00000000e+00 5.34793657e-25 0.00000000e+00]
[ 1.67101349e-25 1.00000000e+00 1.15098012e-22 0.00000000e+00]
[ 4.46111042e-26 1.00000000e+00 1.23599421e-23 0.00000000e+00]
[ 1.31791856e-24 1.00000000e+00 2.25831162e-22 0.00000000e+00]
[ 2.19408324e-12 1.00000000e+00 5.67631081e-11 1.22608556e-23]]
那么肯定还有其他问题。
最佳答案
您的数据集可能不平衡,这将使网络更难训练,因为它倾向于预测最可能的类别。
我认为您的单层模型不够强大,无法在整个数据集上进行训练。您也许应该添加更多层并使用卷积和最大池化。
<小时/>但是,如果您想验证该模型是否可行,请尝试在更少数量的图像(例如:50 张图像)上对其进行训练,并查看它是否会过度拟合这个小型训练集。
关于python - 150x150 图像上的基本 softmax 模型实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38030552/
如何将十进制数字转换为mixed radix表示法? 我猜想给定每个基数数组的输入和十进制数,它应该输出每列值的数组。 最佳答案 伪代码: bases = [24, 60, 60] input = 8
我有 Table-A,其中有“x”行。 (对于这个例子有 8 行) 我通过使用游标创建了列数为“x”的Table-C。 (使其动态化;如果将更多行添加到 Table-A,则会在 Table-C 中创建
我有一个关于对象的(很可能是简单而愚蠢的)问题。我创建了实例“Person”的对象“jon”。当我打电话时 console.log(jon.name) 控制台会给我输出“jon”。到目前为止,一切都很
这个问题已经有答案了: 已关闭11 年前。 Possible Duplicate: javascript function vs. ( function() { … } ()); 抱歉,如果这太基础了
我正在尝试用 Java 重新创建射弹轨迹,但是,我遇到了一些问题。我看过很多解释公式之类的视频,但他们的方程中有一个目标,而我没有。我的意思是,他们有一个范围来计算子弹的下落,但我试图弄清楚子弹最终会
(希望如此)来自一个完整的 Rust 初学者的一个简单问题。我的循环有什么问题? num 计算结果为“69”的速度相当快,但是一旦 num 设置为“69”,循环就永远不会退出。我肯定遗漏了一些明显的东
我在 id="name"的元素上应用“.length”,但它计数为 29 而不是 14。我想知道我的错误在哪里?如果有人可以让我知道,那就太好了。谢谢! var name=document.getEl
我知道这很简单,但由于某种原因我无法让它工作。我正在尝试在 Java 中创建自定义颜色,但它似乎不起作用。 import java.awt.Color; Color deepGreen = new C
我有一个大文件,其中每一行都包含一个子字符串,例如 ABC123。如果我执行 grep ABC file.txt 或 grep ABC1 file.txt 我按预期返回这些行,但如果我执行 grep
我想将以下实体映射转换为 Priority 对象。在 getter 上,当我将“Short”更改为“Priority”并遵循 this.priority 时,它会提示 'basic' 属性类型不应该是
我正在开发一个相当基本的函数,我发现很难弄清楚为什么我会得到我的输出。 def mystery(n): print(n) if n < 4: my
我正在尝试对 WordPress 安装的新闻部分实现同位素过滤。我是 JavaScript/jQuery 的新手,正在尝试随时随地学习。我首先使用 Filters section of the Iso
已关闭。这个问题是 not reproducible or was caused by typos 。目前不接受答案。 这个问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-top
我在另一个实体类中引用一个实体并收到此错误。下面是示例代码。我在 persistence.xml 中也有这些类。 是什么导致了这个问题?我正在使用 Spring 数据 JPA 和 Hibernate。
我正在解析 HTML 并重新格式化图像以使其更好地适应。由于某种原因,当我有多个图像需要解析时,我会超出范围,而且我一生都无法弄清楚为什么。 当 imgArray.count >1 时,我将使用带有递
我是 SQL 新手,正在尝试创建一个基本的子查询。我需要找出经理的平均年龄和实习生的平均年龄之间的差异。 标题为一栏 - 经理或实习生年龄是一列,全部在同一个表中。 我会使用两个子查询来做类似的事情:
我习惯了 csh,所以不得不使用 bash 有点烦人。这段代码有什么问题? if[$time > 0300] && [$time 和 300 && time < 900 )) then mod
我建立了这个页面:http://excelwrestling.com/poola.php即将到来的双重锦标赛。我的大部分数据都是从我的 mySQL 数据库中提取的,现在只有一些示例数据。 我希望链接选
是否有任何原因导致以下内容不起作用: for (i=0;i < someArray.length;i++) { if (someArray[i].indexOf("something") !=
我现在正在学习 Javascript,有一个问题一直困扰着我! 因此,我在这里所需要做的就是在此输入框中键入颜色,单击按钮并将标题更改为键入的颜色(仅当键入的颜色位于变量中指定的数组中时)。 我的代码
我是一名优秀的程序员,十分优秀!