我正在尝试可视化我的模型,但是当我使用 keras 的 plot_model 函数时,它给我错误提示“'InputLayer'对象不可迭代”我正在附加我的代码和错误。请帮忙
model = tf.keras.models.Sequential([
tf.keras.layers.Conv2D(96, (5, 5), activation='relu', input_shape=(28, 28, 3), padding = 'same'),
tf.keras.layers.Conv2D(96, (5, 5), activation='relu', padding = 'same'),
tf.keras.layers.MaxPooling2D(2, 2),
tf.keras.layers.Conv2D(256, (5, 5), activation='relu', padding = 'same'),
tf.keras.layers.Conv2D(256, (5, 5), activation='relu', padding = 'same'),
tf.keras.layers.MaxPooling2D(2, 2),
tf.keras.layers.Conv2D(384, (3, 3), activation='relu', padding = 'same'),
tf.keras.layers.Conv2D(384, (3, 3), activation='relu', padding = 'same'),
tf.keras.layers.MaxPooling2D(2, 2),
tf.keras.layers.Conv2D(256, (3, 3), activation='relu', padding = 'same'),
tf.keras.layers.Conv2D(256, (3, 3), activation='relu', padding = 'same'),
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(2304, activation='relu'),
tf.keras.layers.Dense(2304, activation='relu'),
tf.keras.layers.Dense(10, activation=tf.nn.softmax) …Run Code Online (Sandbox Code Playgroud) python machine-learning conv-neural-network keras tensorflow
我有这张图片,如下所示。它是一个二进制掩码
我使用下面的代码创建了这个图像。基本上我得到了x_idx,对于那些白色像素,并且我知道实际的图像大小,所以我首先创建一个空数组并在和 的y_idx帮助下填充这些行x_idxy_idx
image = np.empty((x_shape, y_shape))
def line_to_img(linedf, image):
x_idx = linedf.x
y_idx = linedf.y
for i,j in zip(x_idx, y_idx):
image[i, j] = 1
return image
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,除了 2 条线(一根在左边,一根在右边)之外,所有像素都是相同的。
正如你所看到的,右边的线不连续,我想通过某种插值方法使这条线连续
我尝试过两种不同的方法来实现这一目标,但到目前为止还没有运气
第一种方法使用skimage
new_image = skimage.morphology.remove_small_holes(old_image, 40, connectivity=2, in_place=False)
输出解释:没有任何插值的相同图像
第二种方法使用cv2
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(3,3))
new_image = cv2.morphologyEx(old_image,cv2.MORPH_OPEN,kernel)
Run Code Online (Sandbox Code Playgroud)
输出解释:由于某种原因该行被删除
请帮助我如何完成此任务并在图像中插入线条以获得连续的线条
编辑(用例):基本上我得到了x_idx,y_idx对于那些白色像素,并且我知道实际的图像大小,所以我首先创建一个空数组并在 的帮助下填充这些行,x_idx并且y_idx我无法控制数据,就是这样,现在我想加入合适尺寸的线。基本上,我必须创建分割标签,其中线上方是一个标签,线下方是一个标签,左侧很好,我可以根据该线将图像分为两个标签,而中间部分将保留对于第 1 类,即上部,虽然我确定右侧是单行,但只是我获得的数据已降级,所以我希望此插值进入图片
python interpolation opencv image-processing image-segmentation
我正在使用 google colab,并且尝试使用“Times New Roman”字体进行 matplotlib 绘图。由于google colab中的ttf文件位于,/usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/fonts/ttf所以我所做的就是下载“Times New Roman”的ttf文件https://github.com/trishume/OpenTuringCompiler/blob/master/stdlib-sfml/fonts/Times%20New%20Roman.ttf并运行一个命令!wget https://github.com/trishume/OpenTuringCompiler/blob/master/stdlib-sfml/fonts/Times%20New%20Roman.ttf -P /usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/fonts/ttf,该命令基本上将tff文件下载到google colab中matplotlib的字体文件夹中。
现在,当我尝试使用matplotlib.font_manager.findfont('Times New Roman')它时,出现了如下所示的错误。因此我无法在绘图中使用该字体。
所以我无法找到问题所在,因为我亲自检查并找到了上述字体的 tff 文件。
请帮忙
!wget https://github.com/trishume/OpenTuringCompiler/blob/master/stdlib-sfml/fonts/Times%20New%20Roman.ttf -P /usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/fonts/ttf
font_manager.findfont('Times New Roman')
Run Code Online (Sandbox Code Playgroud)
/usr/local/lib/python3.6/dist-packages/matplotlib/font_manager.py:1241: UserWarning: findfont: Font family ['Times New Roman'] not found. Falling back to DejaVu Sans.
(prop.get_family(), self.defaultFamily[fontext]))
Run Code Online (Sandbox Code Playgroud)