numpy.argmax

numpy.argmax(a, axis=None, out=None)[source]

Returns the indices of the maximum values along an axis.

Parameters:

a : array_like

Input array.

axis : int, optional

By default, the index is into the flattened array, otherwise along the specified axis.

out : array, optional

If provided, the result will be inserted into this array. It should be of the appropriate shape and dtype.

Returns:

index_array : ndarray of ints

Array of indices into the array. It has the same shape as a.shape with the dimension along axis removed.

See also

ndarray.argmax, argmin

amax
The maximum value along a given axis.
unravel_index
Convert a flat index into an index tuple.

Notes

In case of multiple occurrences of the maximum values, the indices corresponding to the first occurrence are returned.

Examples

>>> a = np.arange(6).reshape(2,3)
>>> a
array([[0, 1, 2],
[3, 4, 5]])
>>> np.argmax(a)
5
>>> np.argmax(a, axis=0)
array([1, 1, 1])
>>> np.argmax(a, axis=1)
array([2, 2])
>>> b = np.arange(6)
>>> b[1] = 5
>>> b
array([0, 5, 2, 3, 4, 5])
>>> np.argmax(b) # Only the first occurrence is returned.
1 在多分类模型训练中,我的使用:org_labels = [0,1,2,....max_label] 从0开始的标记类别
if __name__ == "__main__":
width, height = 32, 32
X, Y, org_labels = load_data(dirname="data", resize_pics=(width, height))
trainX, testX, trainY, testY = train_test_split(X, Y, test_size=0.2, random_state=666)
print("sample data:")
print(trainX[0])
print(trainY[0])
print(testX[-1])
print(testY[-1]) model = get_model(width, height, classes=100) filename = 'cnn_handwrite-acc0.8.tflearn'
# try to load model and resume training
#try:
# model.load(filename)
# print("Model loaded OK. Resume training!")
#except:
# pass # Initialize our callback with desired accuracy threshold.
early_stopping_cb = EarlyStoppingCallback(val_acc_thresh=0.6)
try:
model.fit(trainX, trainY, validation_set=(testX, testY), n_epoch=500, shuffle=True,
snapshot_epoch=True, # Snapshot (save & evaluate) model every epoch.
show_metric=True, batch_size=32, callbacks=early_stopping_cb, run_id='cnn_handwrite')
except StopIteration as e:
print("OK, stop iterate!Good!") model.save(filename) # predict all data and calculate confusion_matrix
model.load(filename) pro_arr =model.predict(X)
predict_labels = np.argmax(pro_arr, axis=1)
print(classification_report(org_labels, predict_labels))
print(confusion_matrix(org_labels, predict_labels))

最新文章

  1. 微信小程序小技巧系列《一》幻灯片,tab导航切换
  2. SDAutolayout图片大小根据数量变化
  3. linux中fork()函数详解
  4. NYOJ-102 次方求模 AC 分类: NYOJ 2014-02-06 18:53 184人阅读 评论(0) 收藏
  5. Cube and EarthDistance
  6. Array.prototype.map()详解
  7. eclipse下使用maven配置库托管jar包
  8. >/dev/null 2>&1 这句话的含义
  9. .NET面试题解答
  10. Http中的Get/Post方法
  11. 使用mysql索引技巧及注意事项
  12. Windbg程序调试系列5-高CPU问题分析
  13. JavaScript中8个常见的陷阱
  14. Linux - PS1
  15. 【轻松前端之旅】CSS入门
  16. C - Reduced ID Numbers 寒假训练
  17. day02---编程语言、python解释器以及变量
  18. Xamarin Android组件篇教程RecylerView动画组件RecylerViewAnimators(1)
  19. 20165311学习基础和C语言基础调查
  20. 【Scala】Scala-Map使用方法

热门文章

  1. es6系列-变量声明
  2. Cesium 显示CZML数据
  3. 算法题1+2+...+N
  4. 启动weblogic域不需要输入密码设置方法
  5. Boost.Asio c++ 网络编程翻译(18)
  6. ASP.Net MVC开发基础学习笔记(8):新建数据页面
  7. react 路由传参
  8. 怎样创建.NET Web Service http://blog.csdn.net/xiaoxiaohai123/article/details/1546941
  9. 关于提高沟通能力的书单 | 章鱼书单zz
  10. kubernetes容器探针检测