想象一下N3分辨率的体积立方体,其中充满了遮挡体素.立方体可以完全填满,或包含弯曲的"隧道",或墙壁 - 或只是一些流浪的体素; 我们现在选择边界立方体的六个面中的任意两个,并尝试找到连接这两个面的线而不击中其中的任何体素.如果存在这样的线条,则面部可以看到彼此,否则,它们将完全被遮挡.
我的问题是:是否存在O(n)(或更好)算法以快速辨别是否可以绘制这样的线?线的确切参数无关紧要.
我在使用光线投射算法检测盒子中的鼠标命中时遇到了不准确的问题.我完全不知道如何正确地解决这个问题,这让我困扰了好几个星期.
使用图片(以[0,0,-30]为中心的框)最容易描述问题:

黑色线代表绘制的实际hitbox,绿色框代表实际看起来被击中的内容.注意它是如何偏移的(如果盒子离原点更远,它似乎变得更大)并且略小于绘制的hitbox.
这是一些相关的代码,
光线投射:
double BBox::checkFaceIntersection(Vector3 points[4], Vector3 normal, Ray3 ray) {
double rayDotNorm = ray.direction.dot(normal);
if(rayDotNorm == 0) return -1;
Vector3 intersect = points[0] - ray.origin;
double t = intersect.dot(normal) / rayDotNorm;
if(t < 0) return -1;
// Check if first point is from under or below polygon
bool positive = false;
double firstPtDot = ray.direction.dot( (ray.origin - points[0]).cross(ray.origin - points[1]) );
if(firstPtDot > 0) positive = true;
else if(firstPtDot < 0) positive = false;
else return -1; …Run Code Online (Sandbox Code Playgroud) 在TensorFlow的新输入管道功能集中,可以使用"group_by_window"功能将记录集合在一起.它在这里的文档中描述:
https://www.tensorflow.org/api_docs/python/tf/contrib/data/Dataset#group_by_window
我不完全理解这里用来描述函数的解释,我倾向于通过例子学习.我无法在互联网上的任何地方找到任何示例代码来实现此功能.有人可以鞭打一个准系统和这个功能的可运行的例子,以显示它是如何工作的,以及给这个功能提供什么?
我知道kd-tree传统上用于存储点,但我想存储线.是否最好在每个交叉点拆分kd-tree的分割线?或者只将端点存储到kd中以便最近邻找到?
我认为应该和它一起使用with tf.device("/gpu:0"),但我应该把它放在哪里?我认为不是:
with tf.device("/gpu:0"):
tf.app.run()
Run Code Online (Sandbox Code Playgroud)
所以,我应该把它在main()功能tf.app,或我使用的估计模型的功能?
编辑:如果这有帮助,这是我的main()功能:
def main(unused_argv):
"""Code to load training folds data pickle or generate one if not present"""
# Create the Estimator
mnist_classifier = tf.estimator.Estimator(
model_fn=cnn_model_fn2, model_dir="F:/python_machine_learning_codes/tmp/custom_age_adience_1")
# Set up logging for predictions
# Log the values in the "Softmax" tensor with label "probabilities"
tensors_to_log = {"probabilities": "softmax_tensor"}
logging_hook = tf.train.LoggingTensorHook(
tensors=tensors_to_log, every_n_iter=100)
# Train the model
train_input_fn = tf.estimator.inputs.numpy_input_fn(
x={"x": train_data},
y=train_labels,
batch_size=64,
num_epochs=None,
shuffle=True)
mnist_classifier.train(
input_fn=train_input_fn, …Run Code Online (Sandbox Code Playgroud) 我正在使用TF 1.4.我的问题是关于tf.estimator.Estimator.
我想控制"丢失和步骤"信息消息的频率,例如:
INFO:tensorflow:loss = 0.00896569, step = 14901 (14.937 sec)
Run Code Online (Sandbox Code Playgroud)
我将tf.estimator.RunConfig传递给Estimator的构造函数.但我认为没有一个参数来控制"丢失和步骤"消息.
我认为参数在_train_model方法的estimator.py中是硬编码的:
worker_hooks.extend([
training.NanTensorHook(estimator_spec.loss),
training.LoggingTensorHook(
{
'loss': estimator_spec.loss,
'step': global_step_tensor
},
every_n_iter=100)
])
Run Code Online (Sandbox Code Playgroud) 我想计算具有给定高度的相机到像素位置(世界坐标)的光线方向,如本文所述.相机图像尺寸为640,480.我校准了固有的相机参数并且不对每个图像进行分类.我测量了相机和背景平面(29厘米)之间的物理距离,如下图所示:

1 cm转换为25像素(假设为二次像素).我的第一种方法是根据像素和摄像机位置进行计算,如下所示:
float3 pixPos = (float3)(u, v, z);
float3 camPos = (float3)(height/2, width/2, 29*25);
float3 ray = normalize(pixPos-camPos);
Run Code Online (Sandbox Code Playgroud)
其中u,v是从0,0到高度的图像坐标,宽度和z是我(已经估计的)高度值.这似乎不是正确的方法.我已经对SO进行了搜索并找到了这个答案,但是那里描述的解决方案不包括像素高度(这里是z).
在tf.estimator,average_loss和之间有什么区别loss?我会从名字中猜到前者将被后者除以记录的数量,但事实并非如此; 有几千条记录,后者大约是前者的三到四倍.
我训练了一个tf.estimator.LinearClassifier.虽然训练和评估模型需要一段合理的时间用于我的数据大小(约60秒),但预测需要更长的时间(约1小时).
预测代码如下:
predictionResult = estimator.predict(input_fn=lambda: my_input_fn2(predictionValidationFile, False, 1))
predictionList = [prediction for prediction in predictionResult]
Run Code Online (Sandbox Code Playgroud)
有:
def my_input_fn2(file_path, perform_shuffle=False, repeat_count=1):
def _parse_function(example_proto):
keys_to_features = {"xslm": tf.FixedLenFeature([10000], tf.float32),
"xrnn": tf.FixedLenFeature([10000], tf.float32),
"target": tf.FixedLenFeature([10000], tf.float32)}
parsed_features = tf.parse_single_example(example_proto, keys_to_features)
myfeatures = {'xrnn':parsed_features['xrnn'], 'xslm':parsed_features['xslm']}
return myfeatures, parsed_features['target']
dataset = (tf.data.TFRecordDataset(file_path)
.map(_parse_function))
dataset = dataset.repeat(repeat_count)
dataset = dataset.batch(1)
iterator = dataset.make_one_shot_iterator()
batch_feature, batch_labels = iterator.get_next()
xs= tf.reshape(batch_feature['xslm'],[-1,1])
xr= tf.reshape(batch_feature['xrnn'],[-1,1])
x = {'xrnn':xr, 'xslm':xs}
y = tf.reshape(batch_labels, [-1,1])
return x, y
Run Code Online (Sandbox Code Playgroud)
当运行10 000个样本(对应于一个批次)时,第二行需要0.8秒才能执行.有500万个样本,预测需要一个多小时.
我在这个阶段的猜测是,这种缓慢的性能仅仅是由于估计器predict()函数返回一个python生成器而不是返回实际的预测结果.对于每个批次,生成器最终会对函数进行10 000次调用以获得10 …
我正在研究一个光线追踪器,但我在阴影部分被困了几天.我的影子表现得很奇怪.这是光线跟踪器的图像:
黑色部分应该是阴影.
光线的原点总是(0.f,-10.f,-500.f),因为这是一个透视投影,它是相机的眼睛.当射线击中一个平面时,击中点始终是射线的原点,但是与球体不同.它是不同的,因为它基于球体的位置.平面和球体之间从不存在交叉,因为原点是巨大的差异.我也尝试在盒子上添加阴影,但这也不起作用.两个球体之间的阴影确实有效!
如果有人想看到交叉口代码,请告诉我.
感谢您抽出宝贵时间来帮助我!
相机
Camera::Camera(float a_fFov, const Dimension& a_viewDimension, vec3 a_v3Eye, vec3 a_v3Center, vec3 a_v3Up) :
m_fFov(a_fFov),
m_viewDimension(a_viewDimension),
m_v3Eye(a_v3Eye),
m_v3Center(a_v3Center),
m_v3Up(a_v3Up)
{
// Calculate the x, y and z axis
vec3 v3ViewDirection = (m_v3Eye - m_v3Center).normalize();
vec3 v3U = m_v3Up.cross(v3ViewDirection).normalize();
vec3 v3V = v3ViewDirection.cross(v3U);
// Calculate the aspect ratio of the screen
float fAspectRatio = static_cast<float>(m_viewDimension.m_iHeight) /
static_cast<float>(m_viewDimension.m_iWidth);
float fViewPlaneHalfWidth = tanf(m_fFov / 2.f);
float fViewPlaneHalfHeight = fAspectRatio * fViewPlaneHalfWidth;
// The bottom left of the plane
m_v3ViewPlaneBottomLeft …Run Code Online (Sandbox Code Playgroud) tensorflow ×5
python ×2
trace ×2
3d ×1
algorithm ×1
c++ ×1
camera ×1
casting ×1
cube ×1
graphics ×1
intersection ×1
kdtree ×1
opengl ×1
performance ×1
pixel ×1
ray-picking ×1
raytracing ×1
shader ×1
voxel ×1