argmax

NumPy 之 案例(随机漫步)

老子叫甜甜 提交于 2019-12-04 12:15:44
import numpy as np The numpy.random module supplements(补充) the built-in Python random with functions for efficiently generating whole arrays of sample values from many kinds of probalility distributions. For example, you can get a 4x4 array of samples from the standard normal distribution using normal: samples = np.random.normal(size=(4,4)) samples array([[-0.49777854, 1.01894039, 0.3542692 , 1.0187122 ], [-0.07139068, -0.44245259, -2.05535526, 0.49974435], [ 0.80183078, -0.11299759, 1.22759314, 1.37571884], [ 0.32086762, -0.79930024, -0.31965109, 0.23004107]]) Python's built-in random module,

What is the meaning of axis=-1 in keras.argmax?

老子叫甜甜 提交于 2019-12-04 07:29:17
问题 I am a beginner in Keras and need help to understand keras.argmax(a, axis=-1) and keras.max(a, axis=-1) . What is the meaning of axis=-1 when a.shape = (19, 19, 5, 80) ? And also what will be the output of keras.argmax(a, axis=-1) and keras.max(a, axis=-1) ? 回答1: This means that the index that will be returned by argmax will be taken from the last axis. Your data has some shape (19,19,5,80) . This means: Axis 0 = 19 elements Axis 1 = 19 elements Axis 2 = 5 elements Axis 3 = 80 elements Now,

[TensorFlow] argmax, softmax_cross_entropy_with_logits, sparse_softmax_cross_entropy_with_logits函数详解

夙愿已清 提交于 2019-12-03 12:59:05
写在前面 tensorFlow版本:1.8.0 一、tf.argmax() tf.argmax( input, axis= None , name= None , dimension= None , output_type=tf.int64 ) 1、argmax()的作用是返回数组某一行或某一列最大数值所在的下标 2、input:输入矩阵 3、 axis:指定按行操作还是按列操作 此函数在使用时最重要的两个参数是input和axis,axis可选的取值是0和1。axis=0表示对矩阵按列进行argmax操作,axis=1表示对矩阵按行进行argmax操作。 举例如下: import tensorflow as tf data = tf.constant( [[1, 5, 4], [2, 3, 6]] , dtype=tf.float32) # 定义一个 2 * 3 的矩阵 argmax_axis_0 = tf.argmax(data, 0 ) # 按列 argmax_axis_1 = tf.argmax(data, 1 ) # 按行 with tf.Session() as sess: value_axis_0 = sess.run(argmax_axis_0) value_axis_1 = sess.run(argmax_axis_1) print ( "value_axis_0

In Tensorflow, how to unravel the flattened indices obtained by tf.nn.max_pool_with_argmax?

匿名 (未验证) 提交于 2019-12-03 03:00:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I meet a problem: After I use the tf.nn.max_pool_with_argmax , I obtain the indices i.e. argmax: A Tensor of type Targmax. 4-D. The flattened indices of the max values chosen for each output. How to unravel the flattened indices back to the coordinates list in Tensorflow? Thank you very much. 回答1: I had the same problem today and I ended up with this solution: def unravel_argmax(argmax, shape): output_list = [] output_list.append(argmax // (shape[2] * shape[3])) output_list.append(argmax % (shape[2] * shape[3]) // shape[3]) return tf.pack

Tensorflow: I get something wrong in accuracy

匿名 (未验证) 提交于 2019-12-03 02:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I just run a simple code and want to get accuracy after training. I load the model that I saved, but when I want to get accuracy, I get something wrong. Why? # coding=utf-8 from color_1 import read_and_decode, get_batch, get_test_batch import AlexNet import cv2 import os import time import numpy as np import tensorflow as tf import AlexNet_train import math batch_size=128 num_examples = 1000 crop_size=56 def evaluate(test_x, test_y): image_holder = tf.placeholder(tf.float32, [batch_size, 56, 56, 3], name='x-input') label_holder = tf

Argmax of each row or column in scipy sparse matrix

匿名 (未验证) 提交于 2019-12-03 01:49:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: scipy.sparse.coo_matrix.max returns the maximum value of each row or column, given an axis. I would like to know not the value, but the index of the maximum value of each row or column. I haven't found a way to make this in an efficient manner yet, so I'll gladly accept any help. 回答1: From scipy version 0.19, both csr_matrix and csc_matrix support argmax() and argmin() methods. 回答2: I would suggest studying the code for moo . _min_or_max_axis where moo is a coo_matrix . mat = mat . tocsc () # for axis=0 mat . sum_duplicates ()

Getting around tf.argmax which is not differentiable

匿名 (未验证) 提交于 2019-12-03 01:34:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've written a custom loss function for my neural network but it can't compute any gradients. I thinks it is because I need the index of the highest value and are therefore using argmax to get this index. As argmax is not differentiable I to get around this but I don't know how it is possible. Can anyone help? 回答1: If you are cool with approximates, import tensorflow as tf import numpy as np sess = tf.Session() x = tf.placeholder(dtype=tf.float32, shape=(None,)) beta = tf.placeholder(dtype=tf.float32) # Pseudo-math for the below # y = sum( i

Start, End and Duration of Maximum Drawdown in Python

匿名 (未验证) 提交于 2019-12-03 01:14:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Given a time series, I want to calculate the maximum drawdown, and I also want to locate the beginning and end points of the maximum drawdown so I can calculate the duration. I want to mark the beginning and end of the drawdown on a plot of the timeseries like this: a busy cat http://oi61.tinypic.com/r9h4er.jpg So far I've got code to generate a random time series, and I've got code to calculate the max drawdown. If anyone knows how to identify the places where the drawdown begins and ends, I'd really appreciate it! import pandas

手写数字识别

匿名 (未验证) 提交于 2019-12-03 00:43:02
tensorflow库内包含mnist,直接加载mnist数据并转为一维数组形式。直接加载的是.gz格式。 import tensorflow .examples .tutorials .mnist .input _data as input_data # 加载mnist数据 mnist = input_data .read _data_sets( "MNIST_data/" , one_hot=True) # one_hot为是否将标签转为一维数组形式 加载数据 图片转为一维数组 建立模型:softmax回归模型 w为可变n*784二维矩阵,b为10数组 w、b变量初始化为0 y=w*x+b 损失函数:交叉熵 训练模型 模型评估 # -*- coding: utf-8 -*- # 读取数据图片,预处理 import tensorflow as tf import tensorflow .examples .tutorials .mnist .input _data as input_data # 加载mnist数据 mnist = input_data .read _data_sets( "MNIST_data/" , one_hot=True) # one_hot为是否将标签转为一维数组形式 # 构建softmax回归模型 sess = tf

tensorflow中tf.argmax和tf.reduce_max

匿名 (未验证) 提交于 2019-12-03 00:22:01
import tensorflow as tf import numpy as np d_scores = {} d_scores[ 0 ] = [[[ 1 , 2 ] , [ 3 , 4 ] , [ 5 , 6 ]] , [[ 7 , 8 ] , [ 9 , 10 ] , [ 11 , 12 ]]] classes = tf.argmax(d_scores[ 0 ] , axis = 1 ) scores = tf.reduce_max(d_scores[ 0 ] , axis = 1 ) with tf.Session() as sess: print (classes.eval()) print (scores.eval()) 结果 [[2 2] import tensorflow as tf import numpy as np d_scores = {} d_scores[ 0 ] = [[[ 1 , 2 ] , [ 3 , 4 ] , [ 5 , 6 ]] , [[ 7 , 8 ] , [ 9 , 10 ] , [ 11 , 12 ]]] classes = tf.argmax(d_scores[ 0 ] , axis = 2 ) scores = tf.reduce_max(d_scores[ 0 ] , axis = 2 ) with tf.Session() as