小编Mah*_*sam的帖子

223
推荐指数
6
解决办法
14万
查看次数

在virtualenv中设置环境变量

我有一个Heroku项目,它使用环境变量来获取其配置,但我使用virtualenv首先在本地测试我的应用程序.

有没有办法在virtualenv中设置远程机器上定义的环境变量?

python heroku environment-variables virtualenv

149
推荐指数
9
解决办法
11万
查看次数

有没有办法获得Bing当天的照片?

有没有办法以编程方式获取Bing背景图像?

Bing的API似乎没有提供这样的功能,也许还有另一种方式?

bing

86
推荐指数
6
解决办法
7万
查看次数

在Jinja2中投入到str

我想转换一个通过url传递给模板的int,但是它表示str函数没有定义.

我该如何解决这个问题?

这是我的代码:

{% extends "base.html" %}

{% block content %}

    {% for post in posts %}
    {% set year = post.date.year %}
    {% set month = post.date.month %}
    {% set day = post.date.day %}
    {% set p = str(year) + '/' + str(month) + '/' + str(day) + '/' + post.slug %}
    <h3>
        <a href="{{ url_for('get_post', ID=p) }}">
            {{ post.title }}
        </a>
    </h3>

        <p>{{ post.content }}</p>
    {% else: %}
            There's nothing here, move along.
    {% endfor %} …
Run Code Online (Sandbox Code Playgroud)

python jinja2

29
推荐指数
2
解决办法
2万
查看次数

片段标签的使用

在Android中,您可以在FragmentTransaction中为Fragment设置标记.

为什么我需要为片段设置标签?

如果Fragment根据其标记更改其行为,这是一种好习惯吗?

android android-fragments

23
推荐指数
1
解决办法
3万
查看次数

插件阻止Eclipse启动

它只是给我一个空白的窗口,并且闪屏不会消失.

我尝试在终端中运行它,结果证明这是一个有问题的插件.

有没有办法在没有GUI的情况下禁用该插件?

有错误日志:

    [org.eclipse.contribution.weaving.jdt] error at org/eclipse/contribution/jdt/IsWovenTester.aj::0 class 'org.eclipse.contribution.jdt.IsWovenTester' is already woven and has not been built in reweavable mode
[org.eclipse.contribution.weaving.jdt] error at org/eclipse/contribution/jdt/IsWovenTester.aj::0 class 'org.eclipse.contribution.jdt.IsWovenTester$WeavingMarker' is already woven and has not been built in reweavable mode
[org.eclipse.jdt.core] warning at org/eclipse/contribution/jdt/sourceprovider/SourceTransformerAspect.aj:106::0 does not match because declaring type is org.eclipse.jdt.core.IOpenable, if match desired use target(org.eclipse.jdt.core.ICompilationUnit) [Xlint:unmatchedSuperTypeInCall]
    see also: org/eclipse/jdt/internal/core/SourceRefElement.java:198::0
[org.eclipse.jdt.ui] warning at org/eclipse/contribution/jdt/sourceprovider/SourceTransformerAspect.aj:106::0 does not match because declaring type is org.eclipse.jdt.core.ITypeRoot, if match desired use target(org.eclipse.jdt.core.ICompilationUnit) [Xlint:unmatchedSuperTypeInCall]
    see also: org/eclipse/jdt/internal/ui/javaeditor/ASTProvider.java:572::0 …
Run Code Online (Sandbox Code Playgroud)

eclipse eclipse-plugin

9
推荐指数
3
解决办法
1万
查看次数

带有自定义对象的 Keras load_model 无法正常工作

环境

正如标题中已经提到的,在尝试加载保存的模型时,我的自定义损失函数出现了问题。我的损失如下:

def weighted_cross_entropy(weights):

    weights = K.variable(weights)

    def loss(y_true, y_pred):
        y_pred = K.clip(y_pred, K.epsilon(), 1-K.epsilon())

        loss = y_true * K.log(y_pred) * weights
        loss = -K.sum(loss, -1)
        return loss

    return loss

weighted_loss = weighted_cross_entropy([0.1,0.9])
Run Code Online (Sandbox Code Playgroud)

所以在训练过程中,我将该weighted_loss函数用作损失函数,一切运行良好。训练完成后,我.h5使用model.save来自 keras API的标准函数将模型保存为文件。

问题

当我尝试通过加载模型时

model = load_model(path,custom_objects={"weighted_loss":weighted_loss})
Run Code Online (Sandbox Code Playgroud)

我得到一个ValueError告诉我损失未知的消息。

错误

错误消息如下所示:

File "...\predict.py", line 29, in my_script
"weighted_loss": weighted_loss})
File "...\Continuum\anaconda3\envs\processing\lib\site-packages\keras\engine\saving.py", line 419, in load_model
model = _deserialize_model(f, custom_objects, compile)
File "...\Continuum\anaconda3\envs\processing\lib\site-packages\keras\engine\saving.py", line 312, in _deserialize_model
sample_weight_mode=sample_weight_mode)
File "...\Continuum\anaconda3\envs\processing\lib\site-packages\keras\engine\training.py", …
Run Code Online (Sandbox Code Playgroud)

python machine-learning keras loss-function

9
推荐指数
1
解决办法
1万
查看次数

python中的Primality测试

我正在尝试在Python中进行简单的素性测试.

根据维基百科,素数测试如下:

给定输入数n,检查从2到n-1的任何整数m是否除以n.如果n可以被任何m整除,则n是复合的,否则它是素数.

我开始排除偶数 - 除了2 - 作为素数的候选人

def prime_candidates(x):
    odd = range(1, x, 2)
    odd.insert(0, 2)
    odd.remove(1)
    return odd
Run Code Online (Sandbox Code Playgroud)

然后根据上面的规则编写一个函数来检查质数.

def isprime(x):
    for i in range(2, x-1):
            if x % i == 0:
                    return False
            else:
                    return True
Run Code Online (Sandbox Code Playgroud)

这是主要功能,它迭代8000个主要候选人的列表并测试他们的素数

def main():
    end = 8000
    candidates = prime_candidates(end)
    for i in candidates:
            if isprime(i) and i < end:
                    print 'prime found ' + str(i)
Run Code Online (Sandbox Code Playgroud)

问题是isprime函数为非素数的数字返回True.

python primes

7
推荐指数
2
解决办法
2万
查看次数

来自scala解释器的Scaladoc

我最近一直在尝试使用Scala,我注意到当我需要查找函数或类时,我必须访问网站或导航到本地文档.

有没有办法从解释器内部读取Scaladoc?

也许像help()Python一样.

scala

6
推荐指数
1
解决办法
742
查看次数

reStructuredText中的小节

我正在尝试在reStructuredText中编写一个文档,但目前我遇到了一个问题.

我希望文档有一个标题,这将是居中的,然后我立即想要一个小节.

我尝试过以下操作

##############
Title
##############

+++++++++
Subtitle
+++++++++
content
Run Code Online (Sandbox Code Playgroud)

但是当我将其转换为PDF时,它使标题和副标题都居中.

restructuredtext

5
推荐指数
1
解决办法
3582
查看次数