我正在为 imdb 情感分析数据集构建文本分类模型。我下载了数据集并按照此处给出的教程进行操作 - https://developers.google.com/machine-learning/guides/text-classification/step-4
我得到的错误是
TypeError: Failed to convert object of type <class 'tensorflow.python.framework.sparse_tensor.SparseTensor'> to Tensor. Contents: SparseTensor(indices=Tensor("DeserializeSparse:0", shape=(None, 2), dtype=int64), values=Tensor("DeserializeSparse:1", shape=(None,), dtype=float32), dense_shape=Tensor("stack:0", shape=(2,), dtype=int64)). Consider casting elements to a supported type.
Run Code Online (Sandbox Code Playgroud)
x_train和x_val的类型是scipy.sparse.csr.csr_matrix。当传递给顺序模型时,这会产生错误。怎么解决?
import tensorflow as tf
import numpy as np
from tensorflow.python.keras.preprocessing import sequence
from tensorflow.python.keras.preprocessing import text
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.feature_selection import SelectKBest
from sklearn.feature_selection import f_classif
# Vectorization parameters
# Range (inclusive) of n-gram sizes for tokenizing text.
NGRAM_RANGE = (1, 2) …Run Code Online (Sandbox Code Playgroud) 尝试获取图像 B,如下所示,但下面的代码给出图像 A [遵循 https://pyimagesearch.com/2021/10/06/opencv-contour-approximation/ 的教程]。mask 指的是绿色区域。
cnts = cv2.findContours(mask.copy(), mode=cv2.RETR_EXTERNAL, method=cv2.CHAIN_APPROX_SIMPLE)
cnts = imutils.grab_contours(cnts)
c = max(cnts, key=cv2.contourArea)
eps = 0.001
peri = cv2.arcLength(c, True)
approx = cv2.approxPolyDP(c, eps * peri, True)
#here np.array of shape [4,1,2] is got.
output = mask.copy()
cv2.drawContours(output, [approx], -1, (0, 255, 0), 3)
(x, y, w, h) = cv2.boundingRect(c)
cv2.putText(output, text, (x, y - 15), cv2.FONT_HERSHEY_SIMPLEX,0.9, (0, 255, 0), 2)
cv2.imshow("Approximated Contour", output)
cv2.waitKey(0)]
Run Code Online (Sandbox Code Playgroud)
如何获得图像B?我认为 drawContours() 不应该用线连接点,但不知道如何获得它。Opencv链接https://docs.opencv.org/3.4/d4/d73/tutorial_py_contours_begin.html不显示获取图像B的代码