小编Ath*_*dom的帖子

Expo 隧道无法工作:CommandError:请安装 @expo/ngrok@^4.1.0 并重试

我正在尝试使用 ngrok 隧道在 iOS 设备上运行我的 Expo 应用程序,因为我当前连接到的公共 WiFi 不允许我的 iOS 设备访问 Macbook 上的 Expo 服务。

\n

首先,我尝试了建议的命令,但即使在全局安装之后,它 npx expo start --tunnel也会出现安装错误。@expo/ngrok

\n
\n

CommandError:请安装@expo/ngrok@^4.1.0并重试

\n
\n
% npx expo start --tunnel\n\nStarting project at /Users/foo/expo-project\nStarting Metro Bundler\n\xe2\x9c\x94 The package @expo/ngrok@^4.1.0 is required to use tunnels, would you like to install it globally? \xe2\x80\xa6 yes\nInstalling @expo/ngrok@^4.1.0...\n> npm install --global @expo/ngrok@^4.1.0\nInstalled @expo/ngrok@^4.1.0\nCommandError: Please install @expo/ngrok@^4.1.0 and try again\n
Run Code Online (Sandbox Code Playgroud)\n

接下来我尝试使用安装 ngrokbrew并在端口 3000 上启动它

\n

在此输入图像描述\n并启动,npx expo start --tunnel …

ngrok react-native expo

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

Python 3 gzip 会关闭 fileobj 吗?

gzipPython 3 的文档指出

\n
\n

调用 GzipFile 对象\xe2\x80\x99s close() 方法不会关闭 fileobj,因为您可能希望在压缩数据后附加更多材料

\n
\n

这是否意味着如果我们执行以下操作,gzip 文件处理程序f_in不会关闭

\n
import gzip\nimport shutil\nwith gzip.open(\'/home/joe/file.txt.gz\', \'rb\') as f_in:\n    with open(\'/home/joe/file.txt\', \'wb\') as f_out:\n        shutil.copyfileobj(f_in, f_out)\n
Run Code Online (Sandbox Code Playgroud)\n

如果是这样,如果多次执行此代码,是否会导致泄漏?

\n

python compression gzip zlib python-3.x

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

使用 Python 共享内存的分段错误

该函数store_in_shm将 numpy 数组写入共享内存,而第二个函数read_from_shm使用同一共享内存空间中的数据创建 numpy 数组并返回 numpy 数组。

但是,在 Python 3.8 中运行代码会出现以下分段错误:

zsh:分段错误 python foo.py

为什么从函数内部访问numpy数组没有问题read_from_shm,但在函数外部再次访问numpy数组时出现分段错误?

输出:

From read_from_shm(): [0 1 2 3 4 5 6 7 8 9]
zsh: segmentation fault  python foo.py
% /Users/athena/opt/anaconda3/envs/test/lib/python3.8/multiprocessing/resource_tracker.py:203: UserWarning: resource_tracker: There appear to be 1 leaked shared_memory objects to clean up at shutdown
  warnings.warn('resource_tracker: There appear to be %d '
Run Code Online (Sandbox Code Playgroud)

foo.py

import numpy as np
from multiprocessing import shared_memory

def store_in_shm(data):
    shm = shared_memory.SharedMemory(name='foo', create=True, size=data.nbytes)
    shmData …
Run Code Online (Sandbox Code Playgroud)

python macos numpy shared-memory python-3.8

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

检查 Numpy 数组是否存储在共享内存中

在 Python 3.8+ 中,是否可以检查 numpy 数组是否存储在共享内存中?

在以下示例中,sharedArr使用对象的缓冲区创建了一个 numpy 数组multiprocessing.shared_memory.SharedMemory。想知道是否可以写一个函数来检测是否SharedMemory被使用。

import numpy as np
from multiprocessing import shared_memory

if __name__ == '__main__':
    # Created numpy array `sharedArr`in shared memory
    arr = np.zeros(5)
    shm = shared_memory.SharedMemory(create=True, size=arr.nbytes)
    sharedArr = np.ndarray(arr.shape, dtype=arr.dtype, buffer=shm.buf)
    sharedArr[:] = arr[:]

    # How to tell if numpy array is stored in shared memory?
    print(type(sharedArr))      # <class 'numpy.ndarray'>
    print(hex(id(sharedArr)))   # 0x7fac99469f30

    shm.close()
    shm.unlink()
Run Code Online (Sandbox Code Playgroud)

python numpy shared-memory sysv python-3.x

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

错误:捆绑Meteor.js应用程序时没有这样的包

当我的Meteor应用程序被捆绑(使用Meteor UP mup deploy)时,它会在下面给出一组错误.在捆绑之前,我是否必须使用Meteorite手动安装(全局?)这些软件包?

$ mup deploy

Meteor-UP : Production Quality Meteor Deployments
--------------------------------------------------

Bundling Started: /var/www/test-app
Bundling Error:  Command failed:
-------------------STDOUT-------------------
rss: updating npm dependencies -- rss...
mailchimp: updating npm dependencies -- mailchimp...
Errors prevented bundling:
While building the application:
error: no such package: 'database-forms'
error: no such package: 'crypto-md5'
error: no such package: 'momentjs'
error: no such package: 'iron-router'
error: no such package: 'nprogress'

-------------------STDERR-------------------
Run Code Online (Sandbox Code Playgroud)

javascript node.js npm meteor meteorite

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

Dataloader 的 PyTorch 自定义数据集分析

我实现了一个自定义 PyTorch 数据集,供项目的数据加载器使用。然而,它的运行速度比预期慢,因此选择分析来解决瓶颈问题。

研究了 vprof,但如果我只对分析数据集实现感兴趣,我不确定要分析的函数。在 Ubuntu 18.04 上使用 PyTorch 1.5 和 Python 3.7。

我们如何仅对自定义数据集实现执行性能分析(CPU 和内存)?

谢谢!

python profiling python-3.x flamegraph pytorch

5
推荐指数
0
解决办法
439
查看次数

正确使用 PyTorch 的 non_blocking=True 进行数据预取

我正在研究在 GPU 上训练模型时将数据从 CPU 预取到 GPU 中。与 GPU 模型训练重叠的 CPU 到 GPU 数据传输似乎需要两者

  1. 将数据传输到 GPU 使用 data = data.cuda(non_blocking=True)
  2. 将数据固定到 CPU 内存使用 train_loader = DataLoader(..., pin_memory=True)

但是,我无法理解在这个官方 PyTorch 示例中是如何执行非阻塞传输的,特别是这个代码块:

for i, (images, target) in enumerate(train_loader):
        # measure data loading time
        data_time.update(time.time() - end)

        if args.gpu is not None:
            images = images.cuda(args.gpu, non_blocking=True)
        if torch.cuda.is_available():
            target = target.cuda(args.gpu, non_blocking=True)

        # compute output
        output = model(images)
        loss = criterion(output, target)
Run Code Online (Sandbox Code Playgroud)

惯于 images.cuda(non_blocking=True)并且target.cuda(non_blocking=True)必须在output = model(images)执行之前完成。由于这是一个同步点,images …

python python-3.x deep-learning pytorch

5
推荐指数
2
解决办法
2407
查看次数

使用 Pytorch Lightning 时如何将指标(例如验证损失)记录到 TensorBoard?

我正在使用 Pytorch Lightning 来训练我的模型(在 GPU 设备上,使用 DDP),TensorBoard 是 Lightning 使用的默认记录器。

我的代码设置为分别记录每个训练和验证步骤的训练和验证损失。

class MyLightningModel(pl.LightningModule):

    def training_step(self, batch):
        x, labels = batch
        out = self(x)
        loss = F.mse_loss(out, labels)
        self.log("train_loss", loss)
        return loss

    def validation_step(self, batch):
        x, labels = batch
        out = self(x)
        loss = F.mse_loss(out, labels)
        self.log("val_loss", loss)
        return loss
Run Code Online (Sandbox Code Playgroud)

TensorBoard在选项卡中正确绘制train_loss和图表。但是,在选项卡中的左侧栏上,仅在 下可见。val_lossSCALERSHPARAMShp_metricMetrics

在此输入图像描述

但是,在HPARAMS选项卡中的左侧栏上,仅hp_metric在 下可见Metrics

在此输入图像描述

我们如何将train_loss和添加val_loss到该Metrics部分?这样,我们就可以使用val_lossinPARALLEL COORDINATES VIEW来代替hp_metric …

python machine-learning tensorboard pytorch pytorch-lightning

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

IntelliJ“Kotlin:执行增量编译分析”永远不会结束

I am learning Kotlin using IntelliJ IDEA Community IDE (first time using both) and after restarting the IDE, a simple file no longer finishes building when attempting to run it.

\n

Under the Build panel, it will be stuck at the task

\n
\n

Kotlin: performing incremental compilation analysis

\n
\n

I let it run this task (16 core 5950X, 128 GB DDR4, Ubuntu 20.04) for 2 days already and there is still no progress. Restarting IntelliJ IDE does not …

android intellij-idea kotlin

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

在 Python 3 中捕获特定的 OSError 异常

在Python 3中,我们如何捕获特定的OSError异常?

我当前的代码捕获了所有OSError,但只OSError: [Errno 12]需要捕获。

try:
    foo()
except OSError as e:
    print('Caught OSError: [Errno12]')
Run Code Online (Sandbox Code Playgroud)

完整的错误消息是:

捕获 OSError: [Errno12] 无法分配内存

我们怎样才能让Python只捕获 的Errno12变体OSError

python error-handling ubuntu python-3.x try-except

4
推荐指数
1
解决办法
7051
查看次数