TCPDF png图像无法循环渲染

时间:2020-03-27 06:24:34

标签: php pdf tcpdf

每个人。我想生成一个可以从mysql数据库中获取png图像并打印的pdf文件。 我的问题是png图像只能打印一次。

这是我的代码:

def jaccard_loss(true, logits, eps=1e-7):
    """Computes the Jaccard loss, a.k.a the IoU loss.
    Note that PyTorch optimizers minimize a loss. In this
    case, we would like to maximize the jaccard loss so we
    return the negated jaccard loss.
    Args:
        true: a tensor of shape [B, H, W] or [B, 1, H, W].
        logits: a tensor of shape [B, C, H, W]. Corresponds to
            the raw output or logits of the model.
        eps: added to the denominator for numerical stability.
    Returns:
        jacc_loss: the Jaccard loss.
    """
    num_classes = logits.shape[1]
    if num_classes == 1:
        true_1_hot = torch.eye(num_classes + 1)[true.squeeze(1)]
        true_1_hot = true_1_hot.permute(0, 3, 1, 2).float()
        true_1_hot_f = true_1_hot[:, 0:1, :, :]
        true_1_hot_s = true_1_hot[:, 1:2, :, :]
        true_1_hot = torch.cat([true_1_hot_s, true_1_hot_f], dim=1)
        pos_prob = torch.sigmoid(logits)
        neg_prob = 1 - pos_prob
        probas = torch.cat([pos_prob, neg_prob], dim=1)
    else:
        true_1_hot = torch.eye(num_classes)[true.squeeze(1)]
        true_1_hot = true_1_hot.permute(0, 3, 1, 2).float()
        probas = F.softmax(logits, dim=1)
    true_1_hot = true_1_hot.type(logits.type())
    dims = (0,) + tuple(range(2, true.ndimension()))
    intersection = torch.sum(probas * true_1_hot, dims)
    cardinality = torch.sum(probas + true_1_hot, dims)
    union = cardinality - intersection
    jacc_loss = (intersection / (union + eps)).mean()
    return (1 - jacc_loss)

这是我的数据库 i use same image for every entry

这是我使用png图片时的输出 The image only printed once

如果我使用JPG格式,则不会有问题。仅带有PNG文件。为什么使用PNG格式是因为我想在我的项目中使用该格式,因此用户可以将图像以PNG格式上载到数据库并以PDF格式打印回来。

1 个答案:

答案 0 :(得分:0)

我认为这可以帮助您

TCPDF - Header image only displays on first page

尝试使用不同的.png图像,而不是在每个循环中都使用相同的图像,如果在链接中可以正常读取,则打印正常,则TCPDF中存在使用相同图像的错误