小编Ben*_*son的帖子

UnpicklingError:遇到加载持久id指令,但未指定perpetitive_load函数

我试图运行一个名为api.py. 在此文件中,我正在加载使用 PyTorch 构建和训练的深度学习模型的 pickle 文件。

\n

api.py \napi.py下面给出的函数是最重要的函数。

\n
def load_model_weights(model_architecture, weights_path):\n  if os.path.isfile(weights_path):\n      cherrypy.log("CHERRYPYLOG Loading model from: {}".format(weights_path))\n      model_architecture.load_state_dict(torch.load(weights_path))\n  else:\n      raise ValueError("Path not found {}".format(weights_path))\n\n        \ndef load_recommender(vector_dim, hidden, activation, dropout, weights_path):\n\n    rencoder_api = model.AutoEncoder(layer_sizes=[vector_dim] + [int(l) for l in hidden.split(\',\')],\n                               nl_type=activation,\n                               is_constrained=False,\n                               dp_drop_prob=dropout,\n                               last_layer_activations=False)\n    load_model_weights(rencoder_api, weights_path) \n    rencoder_api.eval()\n    rencoder_api = rencoder_api.cuda()\n    return rencoder_api\n
Run Code Online (Sandbox Code Playgroud)\n

目录结构

\n
def load_model_weights(model_architecture, weights_path):\n  if os.path.isfile(weights_path):\n      cherrypy.log("CHERRYPYLOG Loading model from: {}".format(weights_path))\n      model_architecture.load_state_dict(torch.load(weights_path))\n  else:\n      raise ValueError("Path not found {}".format(weights_path))\n\n        \ndef …
Run Code Online (Sandbox Code Playgroud)

python serialization pickle deep-learning pytorch

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

如何修复 InsecureRequestWarning:正在向主机发出未经验证的 HTTPS 请求

我正在尝试从 url 下载 zip 文件,但收到以下警告

InsecureRequestWarning: Unverified HTTPS request is being made to host 'www.ons.gov.uk'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings   
Run Code Online (Sandbox Code Playgroud)

我读了一点关于这一点的内容,大多数线程都围绕如何禁用它(如果您知道自己在做什么)以及整个一般概念。据我了解,库默认情况request不能执行证书验证吗?为什么我应该向开源文件发出安全请求?我在这里暴露了自己的一些东西,我该如何解决这个问题?

这是我的代码

import pandas as pd
import requests
from requests.auth import HTTPBasicAuth
from zipfile import ZipFile
import io

url = "https://www.ons.gov.uk/file?uri=%2fpeoplepopulationandcommunity%2fhousing%2fdatasets%2fukhousebuildingpermanentdwellingsstartedandcompleted%2fcurrent/ukhousebuilding.zip"


response = requests.get(url, headers={'User-Agent': 'Mozilla/5.0'}, verify=False)
with ZipFile(io.BytesIO(response.content)) as myzip:
    with myzip.open(myzip.namelist()[0]) as hfile:
        df = pd.read_csv(hfile)

print(df)
Run Code Online (Sandbox Code Playgroud)

显然这个警告只在我使用时出现verify=False,它实际上不应该阻止这个警告吗?

抱歉问了太多问题,但我想了解这里发生的事情。如果我误解了这个概念,请纠正我。

python python-requests

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

究竟如何在PHP中使用blowfish?

可能重复:
使用PHP加密和解密密码的最佳方式?

我最近用PHP做了很多事情,想要建立我的第一个登录/注册系统.因此,我一直在网上做很多阅读,以找出实现这一目标的最佳方法.我遇到了几个指南,我对几个实例感到困惑,在开始这条路之前我想确定一下.

我的问题是我究竟如何使用河豚?我已经读过如果提供适当的盐,crypt()将自动选择河豚.如果是这样的话,是什么让盐河豚适合?

现在,我有一个脚本,它从日期和时间中取出一个盐,一个随机数,然后哈希为盐.那是否可以与河豚一起使用?

php passwords hash crypt blowfish

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

让cProf只给出10个最耗时的任务或者按照时间倒序对它们进行排序

我在终端上运行以下代码行来获取我的程序的配置文件。

python3 -m cProfile -s time main.py
Run Code Online (Sandbox Code Playgroud)

然而它打印的输出是巨大的。我只想知道 10 个最耗时的任务或按升序对它们进行排序。我怎样才能把这个告诉cprof?

python time profiling compilation

9
推荐指数
2
解决办法
6954
查看次数

如何使用 API 在 YouTube 社区选项卡上上传帖子?

我搜索了一些相关内容,但找不到。如何使用 YouTube API 在 YouTube 社区选项卡上上传帖子?v3 不可以吗?

youtube-api

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

Python 像浏览器一样接收推送通知

有没有办法让python像浏览器一样接收网络推送通知?

我有一个带有 Firebase 云消息订阅服务(FCM JavaScript 客户端)的网页,我需要以某种方式接收在 Windows PC 上运行的 python 程序上的通知。

一个想法是打开一个 selenium chrome 浏览器并通过它接收通知,但我没有找到一种从通知接收数据的方法,而且我正在尝试使用自动热键记录所有 Windows 通知并出于我的目的读取日志文件,但是如果这种方法的时间和资源合理的话,也不会。

那么有没有什么办法可以达到这个目的呢?

python push-notification firebase-cloud-messaging

9
推荐指数
0
解决办法
1436
查看次数

无法加载动态库“libcublasLt.so.11”;dlerror: libcublasLt.so.11: 无法打开共享对象文件: 没有这样的文件或目录

我刚刚更新了我的显卡驱动器

sudo apt install nvidia-driver-470
sudo apt install cuda-drivers-470
Run Code Online (Sandbox Code Playgroud)

我决定以这种方式安装它们,因为它们在尝试时受到阻碍sudo apt upgrade。然后我错误地sudo apt autoremove清理了旧包。重新启动计算机以正确设置新驱动程序后,我无法再将 GPU 加速与 Tensorflow 结合使用。

import tensorflow as tf
tf.test.is_gpu_available()
WARNING:tensorflow:From <stdin>:1: is_gpu_available (from tensorflow.python.framework.test_util) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.config.list_physical_devices('GPU')` instead.
2021-12-07 16:52:01.771391: I tensorflow/core/platform/cpu_feature_guard.cc:151] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2 FMA
To enable them in other …
Run Code Online (Sandbox Code Playgroud)

python cuda driver tensorflow

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

Github 仪表板-通过 API 或 RSS 提供信息?

加载 github.com 页面时,我看到一个仪表板提要,其中显示了我关注的所有存储库的“推送”/“加星标”更新列表。

当检查 Chrome 上的“网络”选项卡时,我可以看到此源来自此端点:

https://github.com/dashboard-feed
Run Code Online (Sandbox Code Playgroud)

如何通过 GitHub API 获取此数据?也可以通过 RSS 获取吗?

谢谢

github github-api

8
推荐指数
1
解决办法
306
查看次数

gitea:当 sshd 服务器运行时,内置 ssh 服务器未启动

我的 gitea 版本 1.15.5 在我的树莓派上运行时遇到问题。我似乎内置 ssh 服务器没有启动:

ssh -p 2222 git@myaddress.com
ssh: connect to host myaddress.com port 2222: Connection refused
Run Code Online (Sandbox Code Playgroud)

我已经保证“myaddress.com”指向正确的机器并且防火墙规则已调整。网络界面工作得很好。

当我检查该端口是否确实被 gitea 使用时,我意识到内置的 ssh 服务器没有运行:

sudo lsof -i -P -n | grep LISTEN

sshd        [...]      root    [...]  TCP *:22 (LISTEN)
sshd        [...]      root    [...]  TCP *:22 (LISTEN)
[...]
gitea       [...]       git    [...]  TCP *:3000 (LISTEN)
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,没有进程侦听端口 2222。我有一个内部 sshd 服务器在该计算机上的端口 22 上运行,如果可能的话,我希望将这两个服务器分开。或者问题就在那里,你不能将内置的 gitea ssh 服务器与 sshd 服务器一起使用?

这是我的配置的摘录app.ini

ssh -p 2222 git@myaddress.com
ssh: connect to host myaddress.com port …
Run Code Online (Sandbox Code Playgroud)

ssh gitea

8
推荐指数
1
解决办法
4005
查看次数

如何将现有配置文件与 Selenium Webdriver 一起使用?

我正在尝试使用 Python 的Selenium Webdriver以及Firefox位于<PROFILE-DIR>.

我尝试过的

#!/usr/bin/env python

from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
from selenium.webdriver import Firefox, DesiredCapabilities
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.options import Options

options = Options()
options.profile = '<PROFILE_DIR>'
webdriver = Firefox(options=options)
Run Code Online (Sandbox Code Playgroud)

这会将现有配置文件复制到临时位置。我可以看到它有效,因为我启动的新会话可以访问配置文件的旧cookie等。但这不是我想要的:我想就地使用配置文件。

  • 尝试将配置文件作为“--profile”传递给args功能:将上面的代码更改为
capabilities = DesiredCapabilities.FIREFOX.copy()
capabilities['args'] = '--profile <PROFILE-DIR>'
webdriver = Firefox(desired_capabilities=capabilities)
Run Code Online (Sandbox Code Playgroud)

什么也没做:关闭会话后查看geckodriver.log仍然显示类似的内容Running command: "/usr/bin/firefox" "--marionette" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofileOFKY46",即仍在使用临时配置文件(它甚至不是 …

python firefox selenium-webdriver

7
推荐指数
1
解决办法
1522
查看次数