小编San*_*ani的帖子

Transformer 是如何双向的 - 机器学习

我来自 Google BERT 上下文(来自 Transformers 的双向编码器表示)。我已经完成了架构和代码。人们说这本质上双向。为了使其单向注意,将应用一些掩码。

基本上,转换器将键、值和查询作为输入;使用编码器解码器架构;并注意这些键​​、查询和值。我的理解是我们需要明确地传递令牌,而不是本质上理解这一点的转换器。

有人可以解释一下是什么让变压器本质上是双向的

machine-learning

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

“完成运行local_init_op”后Tensorflow变慢

我有一个来自 github 的基于 tensorflow 的代码,它非常慢。它甚至不打印(即使在为 tf.logging 启用调试模式之后)打印以下内容后发生的事情

信息:tensorflow:完成运行local_init_op。 --> 此行代码执行后需要 20 分钟 INFO:tensorflow:prediction_loop 标记为完成

有人可以告诉在哪里查看和优化吗?
已经检查了以下事项:

  • model_fn : 这在 local_init_op 之前执行
  • 本地文件:检查点文件从本地文件系统保存和加载。所以文件传输延迟不应该是原因
  • warm_start_from:尝试过。对预测时间没有影响

估算器代码:

estimator = tf.contrib.tpu.TPUEstimator(
      use_tpu=FLAGS.use_tpu,
      model_fn=model_fn,
      config=run_config,
      warm_start_from = tf.estimator.WarmStartSettings(
            ckpt_to_initialize_from='/content/ckpt',
        ),
      train_batch_size=FLAGS.train_batch_size,
      predict_batch_size=FLAGS.predict_batch_size)
Run Code Online (Sandbox Code Playgroud)

预测代码:

results = estimator.predict(
          predict_input_fn, yield_single_examples=True, checkpoint_path='/content/ckpt/model.ckpt-10949')
Run Code Online (Sandbox Code Playgroud)

执行这段代码所用的时间:

results = list(results)
Run Code Online (Sandbox Code Playgroud)

python tensorflow tensorflow-estimator

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

图像倾斜 - 无法使用 CV2 检测水平线

在这张图片中,我试图检测水平线。当图像不倾斜时,该代码运行良好。然而,它不适用于这种倾斜的图像。我尝试过这种方法通过直方图检测直角,但很多时候实际上使它更加倾斜 - python-opencv-skew- Correction-for-ocr

图像倾斜

下面是检测水平线的代码:

    gray=cv2.cvtColor(img_final_bin,cv2.COLOR_BGR2GRAY)
    horizontal_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (100,1))
    thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]
    detected_lines = cv2.morphologyEx(thresh, cv2.MORPH_OPEN, horizontal_kernel, iterations=2)
    cnts, hierarchy = cv2.findContours(detected_lines, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)


    boundingBoxes = [list(cv2.boundingRect(c)) for c in cnts]
Run Code Online (Sandbox Code Playgroud)

下面是倾斜校正的代码,它给了我错误的结果:

def correct_skew(image, delta=0.001, limit=3):
    def determine_score(arr, angle):
        data = inter.rotate(arr, angle, reshape=False, order=0)
        histogram = np.sum(data, axis=1)
        score = np.sum((histogram[1:] - histogram[:-1]) ** 2)
        return histogram, score

    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1] 

    print("thresh", thresh.shape)
    thresh1 …
Run Code Online (Sandbox Code Playgroud)

python opencv

2
推荐指数
1
解决办法
899
查看次数