我是pytorch的新手.我读了大量使用张量.data成员的pytorch代码.但我.data在官方文件和谷歌搜索,发现很少.我想.data包含张量中的数据,但我不知道什么时候需要它,什么时候不需要?
它说,我今天收到了警告
不推荐使用softmax_cross_entropy_with_logits(来自tensorflow.python.ops.nn_ops),将来的版本将删除它.更新说明:
TensorFlow的未来主要版本将允许渐变在默认情况下流入backprop上的标签输入.
然后我检查tf.nn.softmax_cross_entropy_with_logits_v2了它的建议,并在下面找到了一些东西
反向传播将发生在logits和标签中.要禁止反向传播到标签中,请先将标签张量传递给stop_gradients,然后再将其传递给此函数.
我不太清楚反向传播会发生在标签上是什么意思,不是标签设置为常量吗?
Assume that a ray actor is defined as below
@ray.remote
class Buffer:
def __init__(self):
self.memory = np.zeros(10)
def modify_data(self, indices, values):
self.memory[indices] = values
def sample(self, size):
indices = np.random.randint(0, 10, size)
return self.memory[indices]
Run Code Online (Sandbox Code Playgroud)
Is it thread-safe to have other actors call methods of Buffer without any lock?
我添加了三个正态分布以获得如下所示的新分布,如何在 python 中根据此分布进行采样?
import matplotlib.pyplot as plt
import scipy.stats as ss
import numpy as np
x = np.linspace(0, 10, 1000)
y1 = [ss.norm.pdf(v, loc=5, scale=1) for v in x]
y2 = [ss.norm.pdf(v, loc=1, scale=1.3) for v in x]
y3 = [ss.norm.pdf(v, loc=9, scale=1.3) for v in x]
y = np.sum([y1, y2, y3], axis=0)/3
plt.plot(x, y, '-')
plt.xlabel('$x$')
plt.ylabel('$P(x)$')
Run Code Online (Sandbox Code Playgroud)
顺便说一句,有没有更好的方法来绘制这样的概率分布?
我现在无法将本地提交推送到github存储库。我收到一条错误消息:
Counting objects: 76, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (75/75), done.
Writing objects: 100% (76/76), 5.23 MiB | 24.67 MiB/s, done.
Total 76 (delta 45), reused 0 (delta 0)
remote: fatal: early EOF
error: RPC failed; curl 55 SSL_write() returned SYSCALL, errno = 32
fatal: The remote end hung up unexpectedly
fatal: The remote end hung up unexpectedly
Everything up-to-date
Run Code Online (Sandbox Code Playgroud)
我已经尝试过这里提供的一些解决方案,但是没有用。
我还尝试推动另一个项目以排除网络问题。尽管花了一些时间,它还是成功了。
我跑了git fsck,收到
git fsck --full
Checking object directories: …Run Code Online (Sandbox Code Playgroud) I follow this instruction and write the following code to create a Dataset for images(COCO2014 training set)
from pathlib import Path
import tensorflow as tf
def image_dataset(filepath, image_size, batch_size, norm=True):
def preprocess_image(image):
image = tf.image.decode_jpeg(image, channels=3)
image = tf.image.resize(image, image_size)
if norm:
image /= 255.0 # normalize to [0,1] range
return image
def load_and_preprocess_image(path):
image = tf.read_file(path)
return preprocess_image(image)
all_image_paths = [str(f) for f in Path(filepath).glob('*')]
path_ds = tf.data.Dataset.from_tensor_slices(all_image_paths)
ds = path_ds.map(load_and_preprocess_image, num_parallel_calls=tf.data.experimental.AUTOTUNE)
ds = ds.shuffle(buffer_size = len(all_image_paths)) …Run Code Online (Sandbox Code Playgroud) 我尝试使用以下代码将其设置x-ticks为 [一月,二月,...]
import matplotlib.pyplot as plt
from matplotlib.dates import MonthLocator, DateFormatter
fig = plt.figure(figsize=[10, 5])
ax = fig.add_subplot(111)
ax.plot(np.arange(1000))
ax.xaxis.set_major_locator(MonthLocator())
ax.xaxis.set_major_formatter(DateFormatter('%b'))
Run Code Online (Sandbox Code Playgroud)
我想知道为什么所有 x-ticks 都消失了?我参考这个实现写了上面的代码
非常感谢。
我很困惑为什么马尔可夫毯子包含孩子的父母.维基百科说
它的孩子的父母也必须被包括在内,因为他们可以用来解释有问题的节点.
但是什么the node in question?我还从BayesiaLab找到了另一个信息.它说
配偶(或共同父母,深绿色)用于切割来自儿童的后裔(蓝色节点)的信息.目标节点略微独立于配偶,但有条件依赖,即当儿童可获得某些证据时.
为什么目标节点和配偶在有关儿童的证据时会变得有条件依赖?儿童可获得一些证据是什么意思?
我希望有人可以帮助澄清它,尤其是.用一个具体的例子.谢谢:)
我正在 tensorflow 中实现的健身房环境(BipedalWalker-v2)中运行强化学习程序。我手动设置了环境的随机种子,tensorflow 和 numpy 如下
os.environ['PYTHONHASHSEED']=str(42)
random.seed(42)
np.random.seed(42)
tf.set_random_seed(42)
env = gym.make('BipedalWalker-v2')
env.seed(0)
config = tf.ConfigProto(intra_op_parallelism_threads=1, inter_op_parallelism_threads=1)
config.gpu_options.allow_growth = True
sess = tf.Session(config=config)
# run the graph with sess
Run Code Online (Sandbox Code Playgroud)
但是,每次运行我的程序时都会得到不同的结果(不更改任何代码)。为什么结果不一致,如果我想获得相同的结果应该怎么做?
我能想到的唯一可能引入随机性的地方(神经网络除外)是
tf.truncated_normal用来生成随机噪声epsilon以实现噪声层np.random.uniform从重放缓冲区中随机选择样本我还发现我在前 10 集中得到的分数非常一致,但随后开始有所不同。损失等其他因素也显示出类似的趋势,但在数字上并不相同。
我还设置了“PYTHONHASHSEED”并按照@jaypops96 的描述使用单线程 CPU,但仍然无法重现结果。上面代码块中的代码已经更新
我有一个目录树
working_dir\
main.py
my_agent\
my_worker.py
my_utility\
my_utils.py
Run Code Online (Sandbox Code Playgroud)
每个文件中的代码如下
""" main.py """
import os, sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from my_agent.my_worker import MyWorker
import ray
ray.init()
workers = [MyWorker.remote(i) for i in range(10)]
ids = [worker.get_id.remote() for worker in workers]
# print(*ids, sep='\n')
print(*ray.get(ids), sep='\n')
Run Code Online (Sandbox Code Playgroud)
""" worker.py """
from my_utility import my_utils
import ray
@ray.remote
class MyWorker():
def __init__(self, id):
self.id = id
def get_id(self):
return my_utils.f(self.id)
Run Code Online (Sandbox Code Playgroud)
""" my_utils.py """
def f(id):
return '{}: Everything is fine...'.format(id)
Run Code Online (Sandbox Code Playgroud)
这是我收到的错误消息的一部分
回溯(最近一次调用最后一次):
文件“/Users/aptx4869/anaconda3/envs/p35/lib/python3.5/site-packages/ray/function_manager.py”,第 616 行,在 fetch_and_register_actor unpickled_class …
python ×8
tensorflow ×3
random ×2
ray ×2
git ×1
github ×1
matplotlib ×1
montecarlo ×1
openai-gym ×1
plot ×1
pytorch ×1
random-seed ×1
tensor ×1
version ×1