我刚训练CNN识别具有张量流的太阳黑子.我的模型与此基本相同.问题是我无法找到关于如何使用训练阶段生成的检查点进行预测的明确解释.
尝试使用标准还原方法:
saver = tf.train.import_meta_graph('./model/model.ckpt.meta')
saver.restore(sess,'./model/model.ckpt')
Run Code Online (Sandbox Code Playgroud)
但后来我无法弄清楚如何运行它.
尝试使用tf.estimator.Estimator.predict()
这样:
# Create the Estimator (should reload the last checkpoint but it doesn't)
sunspot_classifier = tf.estimator.Estimator(
model_fn=cnn_model_fn, model_dir="./model")
# Set up logging for predictions
# Log the values in the "Softmax" tensor with label "probabilities"
tensors_to_log = {"probabilities": "softmax_tensor"}
logging_hook = tf.train.LoggingTensorHook(
tensors=tensors_to_log, every_n_iter=50)
# predict with the model and print results
pred_input_fn = tf.estimator.inputs.numpy_input_fn(
x={"x": pred_data},
shuffle=False)
pred_results = sunspot_classifier.predict(input_fn=pred_input_fn)
print(pred_results)
Run Code Online (Sandbox Code Playgroud)
但它的作用是吐出来的<generator object Estimator.predict at 0x10dda6bf8>
.如果我使用相同的代码,但 …
python machine-learning computer-vision python-3.x tensorflow
我正在尝试训练这个神经网络来对一些数据进行预测。我在一个小数据集(大约 100 条记录)上进行了尝试,效果非常好。然后我插入新的数据集,发现神经网络收敛到 0 输出,并且误差近似收敛于正例数量与示例总数之间的比率。
我的数据集由是/否特征 (1.0/0.0) 组成,基本事实也是是/否。
我的假设:
1)有一个输出为0的局部最小值(但我尝试了学习率和初始权重的许多值,它似乎总是收敛在那里)
2)我的权重更新是错误的(但对我来说看起来不错)
3)这只是一个输出缩放问题。我尝试缩放输出(即输出/最大(输出)和输出/平均值(输出)),但结果并不好,正如您在下面提供的代码中看到的那样。我应该以不同的方式缩放它吗?软最大?
这是代码:
import pandas as pd
import numpy as np
import pickle
import random
from collections import defaultdict
alpha = 0.1
N_LAYERS = 10
N_ITER = 10
#N_FEATURES = 8
INIT_SCALE = 1.0
train = pd.read_csv("./data/prediction.csv")
y = train['y_true'].as_matrix()
y = np.vstack(y).astype(float)
ytest = y[18000:]
y = y[:18000]
X = train.drop(['y_true'], axis = 1).as_matrix()
Xtest = X[18000:].astype(float)
X = X[:18000]
def tanh(x,deriv=False):
if(deriv==True):
return (1 - np.tanh(x)**2) * alpha …
Run Code Online (Sandbox Code Playgroud) python classification machine-learning neural-network python-2.7
我需要用python读取bmp文件的标题。我这样试过,但它显然只返回一堆不可理解的字节:
f = open(input_filename,"rb")
data = bytearray(f.read())
f.close()
print(data[:14])
Run Code Online (Sandbox Code Playgroud)
我的想法是找到一个模块或一些快速的东西,以便在打开它时记录图像信息。我知道这个功能的MATLAB中,做正是我想要的:imfinfo()
。但我在 python 中找不到对应物。
需要明确的是,这就是我使用 matlab 得到的结果:
FileModDate: '20-Oct-2017 09:42:24'
FileSize: 1311798
Format: 'bmp'
FormatVersion: 'Version 3 (Microsoft Windows 3.x)'
Width: 1280
Height: 1024
BitDepth: 8
ColorType: 'indexed'
FormatSignature: 'BM'
NumColormapEntries: 256
Colormap: [256x3 double]
RedMask: []
GreenMask: []
BlueMask: []
ImageDataOffset: 1078
BitmapHeaderSize: 40
NumPlanes: 1
CompressionType: 'none'
BitmapSize: 1310720
HorzResolution: 0
VertResolution: 0
NumColorsUsed: 256
NumImportantColors: 0
Run Code Online (Sandbox Code Playgroud)