mean

python实现抠图

送分小仙女□ 提交于 2019-11-28 19:57:23
import numpy as np import cv2 from matplotlib import pyplot as plt img = cv2.imread('b.jpg') mask = np.zeros(img.shape[:2], np.uint8) bgdModel = np.zeros((1, 65), np.float64) fgdModel = np.zeros((1, 65), np.float64) rect = (20, 20, 413, 591) cv2.grabCut(img, mask, rect, bgdModel, fgdModel, 10, cv2.GC_INIT_WITH_RECT) mask2 = np.where((mask == 2) | (mask == 0), 0, 1).astype('uint8') img = img * mask2[:, :, np.newaxis] img += 255 * (1 - cv2.cvtColor(mask2, cv2.COLOR_GRAY2BGR)) # plt.imshow(img) # plt.show() img = np.array(img) mean = np.mean(img) img = img - mean img = img * 0.9 + mean * 0.9 img

python抠图

一曲冷凌霜 提交于 2019-11-28 19:55:29
使用python和opencv进行抠图 其中使用了opencv中的grabcut方法 直接上代码 # encoding:utf-8 # 图像提取 # create by import numpy as np import cv2 from matplotlib import pyplot as plt img = cv2.imread('1.jpg') mask = np.zeros(img.shape[:2], np.uint8) bgdModel = np.zeros((1, 65), np.float64) fgdModel = np.zeros((1, 65), np.float64) rect = (20, 20, 413, 591) cv2.grabCut(img, mask, rect, bgdModel, fgdModel, 10, cv2.GC_INIT_WITH_RECT) mask2 = np.where((mask == 2) | (mask == 0), 0, 1).astype('uint8') img = img * mask2[:, :, np.newaxis] img += 255 * (1 - cv2.cvtColor(mask2, cv2.COLOR_GRAY2BGR)) # plt.imshow(img) # plt.show() img =

typeerror: app.use() requires middleware function

允我心安 提交于 2019-11-28 19:10:44
I am learning node.js with express template engine, I am following udemy course "learn node.js by building 10 projects", while following a lecture when professor run npm start localhost:3000 starts while mine pops up error indicating app.use requires middleware function I have tried matching code and its same. Please help me to resolve the error i have been stuck here for hours tried a lot of edits but its not working for me. When I am trying to run 'npm start' following error pops up TypeError: app.use() requires middleware functions Here is app.js code: var express = require('express'); var

werkzeug.routing.BuildError: Could not build url for endpoint 'index'. Did you mean 'user.index' instead?

帅比萌擦擦* 提交于 2019-11-28 13:52:33
werkzeug.routing.BuildError: Could not build url for endpoint 'index'. Did you mean 'user.index' instead? 前言 因为边学边写的缘故,路由慢慢变多。今天采用蓝图的方法分离,大量的页面要更改, Did you mean 'user.index' instead 这句话也是错误的提示,所以遇到这个问题一时间找不到头绪。 解决 慢慢添加有 url_for 的py和html,更正相应的错误 值得注意的是,即使html代码注释后,jinja2仍然能识别到错误的 url_for ,并报错。 来源: https://www.cnblogs.com/yywBlogW/p/11409731.html

软件工程学习进度第八周暨暑期学习进度之第八周汇总

流过昼夜 提交于 2019-11-28 13:12:33
本周的主要工作是win10+TensorFlow环境下的FCN全卷积神经网络的实现 FCN对图像进行像素级的分类,从而解决了语义级别的图像分割问题。与经典的CNN在卷积层使用全连接层得到固定长度的特征向量进行分类不同,FCN可以接受任意尺寸的输入图像,采用反卷积层对最后一个卷基层的特征图(feature map)进行上采样,使它恢复到输入图像相同的尺寸,从而可以对每一个像素都产生一个预测,同时保留了原始输入图像中的空间信息,最后奇偶在上采样的特征图进行像素的分类。它与卷积神经网络(CNN)的本质区别就是将卷积神经网络的全连层换成卷积层。 本来是打算复现FCN官方代码,后来发现官方使用的是Ubuntu+caffe,本机VMware未装Ubuntu系统所以改写FCN官方代码,并使用win10+TensorFlow实现 在这里使用的是VGG-19的模型和数据集训练 模型下载地址: http://www.vlfeat.org/matconvnet/models/beta16/imagenet-vgg-verydeep-19.mat 数据集下载地址: http://data.csail.mit.edu/places/ADEchallenge/ADEChallengeData2016.zip 文件结构: 训练效果图: 这里看到1000次训练结果loss较低,后续结果大多在3.0左右浮动

【转载】Bandits for Recommendation Systems (Part I)

早过忘川 提交于 2019-11-28 13:03:55
[原文链接: http://engineering.richrelevance.com/bandits-recommendation-systems/ 。] [本文链接: http://www.cnblogs.com/breezedeus/p/3775316.html ,转载请注明出处] Bandits for Recommendation Systems 06/02/2014 • Topics: Bayesian , Big data , Data Science by Sergey Feldman This is the first in a series of three blog posts on bandits for recommendation systems. In this blog post, we will discuss the bandit problem and how it relates to online recommender systems. Then, we'll cover some classic algorithms and see how well they do in simulation. A common problem for internet-based companies is: which piece of

Element-wise mean in R

旧街凉风 提交于 2019-11-28 11:53:06
In R, I have two vectors: a <- c(1, 2, 3, 4) b <- c(NA, 6, 7, 8) How do I find the element-wise mean of the two vectors, removing NA, without a loop? i.e. I want to get the vector of (1, 4, 5, 6) I know the function mean() , I know the argument na.rm = 1 . But I don't know how to put things together. To be sure, in reality I have thousands of vectors with NA appearing at various places, so any dimension-dependent solution wouldn't work. Thanks. how about: rowMeans(cbind(a, b), na.rm=TRUE) or colMeans(rbind(a, b), na.rm=TRUE) I'm not exactly sure what you are asking for, but does apply(rbind(a

How to unscale the coefficients from an lmer()-model fitted with a scaled response

删除回忆录丶 提交于 2019-11-28 09:24:11
I fitted a model in R with the lmer() -function from the lme4 package. I scaled the dependent variable: mod <- lmer(scale(Y) ~ X + (X | Z), data = df, REML = FALSE) I look at the fixed-effect coefficients with fixef(mod) : > fixef(mod) (Intercept) X1 X2 X3 X4 0.08577525 -0.16450047 -0.15040043 -0.25380073 0.02350007 It is quite easy to calculate the means by hand from the fixed-effects coefficients. However, I want them to be unscaled and I am unsure how to do this exactly. I am aware that scaling means substracting the mean from every Y and deviding by the standard deviation. But both, mean

Sklearn 中的朴素贝叶斯分类器

天大地大妈咪最大 提交于 2019-11-28 09:13:22
原文地址: Naive Bayes Classification With Sklearn 原文作者: Martin Müller 译文出自: 掘金翻译计划 本文永久链接: https://github.com/xitu/gold-miner/blob/master/TODO1/naive-bayes-classifier-sklearn-python-example-tips.md 译者: sisibeloved 校对者: rockyzhengwu Sklearn 中的朴素贝叶斯分类器 用豆机实现的高斯分布 这篇 教程 详述了 朴素贝叶斯分类器 的算法、它的 原理 及 优缺点 ,并提供了一个使用 Sklearn 库 的示例。 背景 以著名的 泰坦尼克号遇难者数据集 为例。它收集了泰坦尼克号的乘客的个人信息以及是否从那场海难中生还。让我们试着用乘客的船票费用来预测一下他能否生还。 泰坦尼克号上的 500 名乘客 假设你随机取了 500 名乘客。在这些样本中, 30% 的人幸存下来。幸存乘客的平均票价为 100 美元 ,而遇难乘客的平均票价为 50 美元 。现在,假设你有了一个新的乘客。你不知道他是否幸存,但你知道他买了一张 30 美元 的票穿越大西洋。请你预测一下这个乘客是否幸存。 原理 好吧,你可能回答说这个乘客 没能幸存 。为什么?因为根据上文所取的乘客的随机子集中所包含的信息

numpy.mean on varying row size

自古美人都是妖i 提交于 2019-11-28 08:51:59
问题 The numpy mean function works perfectly fine when the dimensions are the same. a = np.array([[1, 2], [3, 4]]) a.mean(axis=1) array([ 1.5, 3.5]) But if I do it with varrying row size it gives an error a = np.array([[1, 2], [3, 4, 5]]) a.mean(axis=1) IndexError: tuple index out of range I cannot find anything on the documentation regarding this problem. I could calculate the mean myself but I would like to use the build in function for this, seeing that it should be possible. 回答1: Here's an