我在Django 1.11中有一个弃用警告:
RemovedInDjango20Warning: Passing a 3-tuple to django.conf.urls.include() is deprecated. Pass a 2-tuple containing the list of patterns and app_name, and provide the namespace argument to include() instead.
url(r'^admin/', include(admin.site.urls))
Run Code Online (Sandbox Code Playgroud)
在Django 2.0中,这给出了错误:
django.core.exceptions.ImproperlyConfigured: Passing a 3-tuple to include() is not supported.
Pass a 2-tuple containing the list of patterns and app_name, and provide the namespace argument to include() instead.
Run Code Online (Sandbox Code Playgroud)
我该怎么改变url(r'^admin/', include(admin.site.urls))?我试着查看文档,但我不知道......
这是我的urls.py:
from django.conf.urls import include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^admin/django-ses/', …Run Code Online (Sandbox Code Playgroud) 我正在维护一个项目,Travis CI已经实施,并且从一天开始.我的所有构建都开始失败,没有我接触任何东西或任何依赖更新...
我想Travis改变了一些东西,我试图调查,但说实话,我不知道.
如果我运行一个完美工作的先前构建,现在每次打电话都会失败 python manage.py ##whatever##
$ python manage.py collectstatic --noinput
Traceback (most recent call last):
File "manage.py", line 35, in <module>
execute_from_command_line(sys.argv)
File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/django/core/management/__init__.py", line 357, in execute
django.setup()
File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/django/apps/registry.py", line 81, in populate
raise RuntimeError("populate() isn't reentrant")
RuntimeError: populate() isn't reentrant
Run Code Online (Sandbox Code Playgroud)
顺便说一句,我使用Python 3.6和3.5获得完全相同的错误.
$ python manage.py collectstatic --noinput
Traceback (most recent call last):
File "manage.py", line 35, in <module>
execute_from_command_line(sys.argv)
File "/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/django/core/management/__init__.py", …Run Code Online (Sandbox Code Playgroud) 我正在使用CircleCI来构建一个项目,一切运行正常,除了我的标签在推送到github时没有构建:
我不明白为什么,我已将整个配置减少到简约配置文件,它是相同的逻辑:
version: 2
jobs:
my_dummy_job_nightly:
working_directory: ~/build
docker:
- image: docker:git
steps:
- checkout
- setup_remote_docker:
reusable: true
exclusive: true
- run:
name: NIGHTLY BUILD
command: |
apk add --update py-pip
python -m pip install --upgrade pip
my_dummy_job_deploy:
working_directory: ~/build
docker:
- image: docker:git
steps:
- checkout
- setup_remote_docker:
reusable: true
exclusive: true
- run:
name: RELEASE BUILD
command: |
apk add --update py-pip
python -m pip install --upgrade pip
###################################################################################
# CircleCI WORKFLOWS #
###################################################################################
workflows: …Run Code Online (Sandbox Code Playgroud) continuous-integration release continuous-deployment circleci
我正在使用最新版本的 Django 和 Django Rest Framework。我的 Web 应用程序提供了一个当前仅由前端使用的 API。
我正在使用相同的 API 路由创建 chrome 扩展。
当我使用本地服务器runserver 命令时,我没有问题。当服务器在 HTTPS 后面运行时,我始终有 403 错误。
{"detail":"CSRF Failed: Referer checking failed - no Referer."}
Run Code Online (Sandbox Code Playgroud)
我使用的视图如下:
@method_decorator(csrf_exempt, name='dispatch')
class ObtainAuthToken(APIView):
permission_classes = (AllowAny,) #maybe not needed in your case
def post(self, request):
username = request.POST['username'].lower()
password = request.POST['password']
user = authenticate(username=username, password=password)
payload = dict()
if user is not None:
token, created = Token.objects.get_or_create(user=user)
payload['token'] = token.key
payload ["success"] = True
else:
payload['error'] = "Credentials …Run Code Online (Sandbox Code Playgroud) django ajax google-chrome-extension django-csrf csrf-protection
我们正在开发一个python库,并希望改变某些函数中某些函数参数的命名方式.
我们希望保持向后兼容性,因此我们希望找到一种为函数参数创建别名的方法.
这是一个例子:
旧版:
class MyClass(object):
def __init__(self, object_id):
self.id = object_id
Run Code Online (Sandbox Code Playgroud)
新版本:
class MyClass(object):
def __init__(self, id_object):
self.id = id_object
Run Code Online (Sandbox Code Playgroud)
我们如何使类与两种调用方式兼容:
object1 = MyClass(object_id=1234)
object2 = MyClass(id_object=1234)
Run Code Online (Sandbox Code Playgroud)
我当然可以创建这样的东西:
class MyClass(object):
def __init__(self, object_id=None, id_object=None):
if id_object is not None:
self.id = id_object
else:
self.id = object_id
Run Code Online (Sandbox Code Playgroud)
但是,它会改变参数的数量,我们严格要避免这种情况.
有没有办法声明方法别名或参数别名?
我想使用Keras层:
from keras.layers.convolutional import UpSampling2D
x = UpSampling2D((2, 2))(x)
Run Code Online (Sandbox Code Playgroud)
如何使用原生tensorflow复制此行为?
我无法找到一个等效的函数/图层.
我们假设我有一个二进制40*40矩阵.在此矩阵中,值可以是1或0.
我需要解析整个矩阵,对于任何值== 1,应用以下内容:
如果满足以下条件,请保持值= 1,否则将值修改回0:
条件:在N*N(以当前评估值为中心)的平方中,我可以计算至少M个值== 1.
N和M是可以为算法设置的参数,当然N<20(在这种情况下)和M<(N*N - 1).
显而易见的算法是迭代整个图像,然后每次值== 1.围绕该值执行另一次搜索.它会产生一个O ^ 3复杂的算法.有没有想过提高效率?
让我们创建一个随机初始化的40*40矩阵1和0.5%(任意选择)的值为1,95%为0.
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline
def display_array(image):
image_display_ready = image * 255
print(image_display_ready)
plt.imshow(image_display_ready, cmap='gray')
plt.show()
image = np.zeros([40,40])
for _ in range(80): # 5% of the pixels are == 1
i, j = np.random.randint(40, size=2)
image[i, j] = 1
# Image displayed on left below before preprocessing
display_array(image)
def cleaning_algorithm_v1(src_image, …Run Code Online (Sandbox Code Playgroud) 我使用 PyAV 库,因为它是 Python 可用的最快库之一。
这是我想使用的一个简单的代码示例:
import av
video = av.open("My_Super_Video.mp4")
total_frames = # ????
for i, frame in enumerate(video.decode(video=0)):
img = frame.to_image() # PIL image
print("Frame: %d/%d ..." % (i, total_frames))
Run Code Online (Sandbox Code Playgroud)
显然我可以使用其他库来加载该库,但是如果可能的话,我更喜欢使用 PyAV,因为它的处理速度很快。
问题1:用PyAV可以获取帧数吗?如果是,怎么办?
问题2:在这种情况下,我会考虑使用另一个库来逐帧加载和处理视频。哪个库可以让我以尽可能最高的速度完成上述操作。我知道以下内容,但不知道它们如何比较:
我正在配置 CircleCI 以自动构建我贡献的开源库的多个容器并将其上传到 Docker Hub。
一切正常,除了当我尝试使用 CLI 登录 docker 时。我认为我的构建无法访问私有环境变量,但是我尝试了一切来修复它......
我的配置文件如下:
version: 2
jobs:
build:
working_directory: ~/build
docker:
- image: docker:git
steps:
- checkout
- setup_remote_docker:
reusable: true
exclusive: true
- run:
name: Connect to Docker Hub
command: |
docker login -u ${DOCKER_USER} -p ${DOCKER_PASS}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
#!/bin/sh -eo pipefail
docker login -u $DOCKER_USER -p $DOCKER_PASS
"docker login" requires at most 1 argument.
See 'docker login --help'.
Usage: docker login [OPTIONS] [SERVER] [flags]
Log in to a …Run Code Online (Sandbox Code Playgroud) 我对BatchNorm(后来的BN)的理解有疑问.
我有一个很好的工作,我正在编写测试来检查形状和输出范围.我注意到当我设置batch_size = 1时,我的模型输出零(logits和激活).
我用BN制作了最简单的节目原型:
输入=> Conv + ReLU => BN => Conv + ReLU => BN => Conv Layer + Tanh
使用xavier初始化初始化模型.我猜测训练期间的 BN 做了一些需要Batch_size> 1的计算.
我在PyTorch中发现了一个似乎在谈论这个问题:https://github.com/pytorch/pytorch/issues/1381
有人能解释一下吗?它对我来说仍然有点模糊.
示例运行:
重要说明:此脚本需要运行Tensorlayer Library:pip install tensorlayer
import tensorflow as tf
import tensorlayer as tl
import numpy as np
def conv_net(inputs, is_training):
xavier_initilizer = tf.contrib.layers.xavier_initializer(uniform=True)
normal_initializer = tf.random_normal_initializer(mean=1., stddev=0.02)
# Input Layers
network = tl.layers.InputLayer(inputs, name='input')
fx = [64, 128, 256, 256, 256]
for i, n_out_channel …Run Code Online (Sandbox Code Playgroud) machine-learning deep-learning conv-neural-network tensorflow batch-normalization
我正在尝试使用python的multiprocessing Pool方法pytorch来处理图像。这是代码:
from multiprocessing import Process, Pool
from torch.autograd import Variable
import numpy as np
from scipy.ndimage import zoom
def get_pred(args):
img = args[0]
scale = args[1]
scales = args[2]
img_scale = zoom(img.numpy(),
(1., 1., scale, scale),
order=1,
prefilter=False,
mode='nearest')
# feed input data
input_img = Variable(torch.from_numpy(img_scale),
volatile=True).cuda()
return input_img
scales = [1,2,3,4,5]
scale_list = []
for scale in scales:
scale_list.append([img,scale,scales])
multi_pool = Pool(processes=5)
predictions = multi_pool.map(get_pred,scale_list)
multi_pool.close()
multi_pool.join()
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
`RuntimeError: Cannot re-initialize CUDA in forked subprocess. …Run Code Online (Sandbox Code Playgroud)