识别:
import tensorflow as tf
import numpy as np
from tensorflow.keras import layers, models
from tensorflow.keras.utils import to_categorical
from tensorflow.keras.preprocessing.image import load_img, img_to_array
# 加载并预处理图像
def load_and_preprocess_image(image_path):
img = load_img(image_path, color_mode='grayscale', target_size=(6, 6))
img_array = img_to_array(img)
img_array = img_array.astype('float32') / 255.0 # 归一化到0-1之间
return img_array
# 标签
labels = [
[[0, 0, 0, 0, 0, 0],
[0, 1, 2, 0, 0, 0],
[2, 1, 0, 0, 0, 0],
[0, 0, 0, 2, 1, 0],
[0, 0, 0, 1, 2, 0],
[0, 0, 0, 0, 0, 0]],
[[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0]],
[[0, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 0],
[0, 0, 0, 1, 0, 0],
[0, 0, 0, 0, 0, 0]],
[[0, 0, 0, 0, 0, 0],
[0, 0, 2, 0, 0, 0],
[2, 0, 0, 0, 0, 0],
[0, 0, 0, 2, 0, 0],
[0, 0, 0, 0, 2, 0],
[0, 0, 0, 0, 0, 0]],
]
# 转换标签为 one-hot 编码
labels = np.array([to_categorical(label, num_classes=3) for label in labels])
# 加载图像数据
image_paths = ['d:/weiqi/wq001.png', 'd:/weiqi/wq002.png', 'd:/weiqi/wq003.png', 'd:/weiqi/wq004.png']
images = np.array([load_and_preprocess_image(path) for path in image_paths])
# 构建CNN模型
model = models.Sequential([
layers.Conv2D(32, (3, 3), activation='relu', padding='same', input_shape=(6, 6, 1)),
layers.Flatten(),
layers.Dense(128, activation='relu'),
layers.Dense(6 * 6 * 3, activation='softmax'), # 输出18个分类
])
model.compile(optimizer='adam',
loss='categorical_crossentropy',
metrics=['accuracy'])
# 将标签 reshape 成模型所需的形状
labels = labels.reshape((labels.shape[0], 6 * 6 * 3))
# 训练模型
model.fit(images, labels, epochs=10)
# 测试模型
test_image = load_and_preprocess_image('d:/weiqi/wq005.png')
test_image = np.expand_dims(test_image, axis=0) # 添加一个批次维度
prediction = model.predict(test_image)
prediction = prediction.reshape((6, 6, 3))
predicted_labels = np.argmax(prediction, axis=2)
print("预测标签:")
print(predicted_labels)
起点python:
import numpy as np
import matplotlib.pyplot as plt
def draw_circle(img, center, radius, value, fill=False):
"""在图像上绘制一个圆"""
a, b = center
for x in range(center[0] - radius, center[0] + radius):
for y in range(center[1] - radius, center[1] + radius):
if (x - a)**2 + (y - b)**2 <= radius**2:
if fill or (x - a)**2 + (y - b)**2 >= (radius-1)**2:
img[x, y] = value
else:
img[x,y]=0
def generate_go_board(N, M, board_size=20):
# 计算图像的尺寸
img_size = (N * board_size, M * board_size)
img = np.zeros((img_size[0], img_size[1]), dtype=int)
# 绘制网格
for i in range(N):
for j in range(M):
x = i * board_size + board_size // 2
x1=board_size // 2
x2=x-x1
y = j * board_size + board_size // 2
y1=board_size//2
y2=y-y1
img[x, y1:(y+1)] = 1 # 横线
img[x1:x, y] = 1 # 竖线
# 添加黑子(实心圆)和白子(空心圆)
black_positions = [ (1,1),(2, 1), (4, 3), (3,4)] # 黑子位置
white_positions = [(2,0),(1, 2), (3, 3), (4,4)] # 白子位置
for pos in black_positions:
center = (pos[0] * board_size + board_size // 2, pos[1] * board_size + board_size // 2)
draw_circle(img, center, board_size // 3, 1, fill=True)
for pos in white_positions:
center = (pos[0] * board_size + board_size // 2, pos[1] * board_size + board_size // 2)
draw_circle(img, center, board_size // 3, 1, fill=False)
return img
# 测试生成 4列5行 的围棋棋盘
M = 5
N = 6
board = generate_go_board(N, M)
# 显示结果
plt.imshow(board, cmap='gray')
plt.axis('equal')
plt.show()
# 打印结果
for row in board:
# print("\t".join(map(str, row)))
print("".join(map(str, row)))
生成图像:
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000111111111111111111111111111111111111111111111111111111111111111111111111111111111000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000001111111000000000000011111110000000000000000100000000000000000001000000000
0000000000100000000000000011111111100000000000110010011000000000000000100000000000000000001000000000
0000000000100000000000000111111111110000000001100010001100000000000000100000000000000000001000000000
0000000000100000000000000111111111110000000001000010000100000000000000100000000000000000001000000000
0000000000100000000000000111111111110000000001000010000100000000000000100000000000000000001000000000
0000000000111111111111111111111111111111111111111111111111111111111111111111111111111111111000000000
0000000000100000000000000111111111110000000001000010000100000000000000100000000000000000001000000000
0000000000100000000000000111111111110000000001000010000100000000000000100000000000000000001000000000
0000000000100000000000000111111111110000000001100010001100000000000000100000000000000000001000000000
0000000000100000000000000011111111100000000000110010011000000000000000100000000000000000001000000000
0000000000100000000000000001111111000000000000011111110000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000111111100000000000001111111000000000000000010000000000000000000100000000000000000001000000000
0000001100100110000000000011111111100000000000000010000000000000000000100000000000000000001000000000
0000011000100011000000000111111111110000000000000010000000000000000000100000000000000000001000000000
0000010000100001000000000111111111110000000000000010000000000000000000100000000000000000001000000000
0000010000100001000000000111111111110000000000000010000000000000000000100000000000000000001000000000
0000110000111111111111111111111111111111111111111111111111111111111111111111111111111111111000000000
0000010000100001000000000111111111110000000000000010000000000000000000100000000000000000001000000000
0000010000100001000000000111111111110000000000000010000000000000000000100000000000000000001000000000
0000011000100011000000000111111111110000000000000010000000000000000000100000000000000000001000000000
0000001100100110000000000011111111100000000000000010000000000000000000100000000000000000001000000000
0000000111111100000000000001111111000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000111111100000000000001111111000000
0000000000100000000000000000001000000000000000000010000000000000001100100110000000000011111111100000
0000000000100000000000000000001000000000000000000010000000000000011000100011000000000111111111110000
0000000000100000000000000000001000000000000000000010000000000000010000100001000000000111111111110000
0000000000100000000000000000001000000000000000000010000000000000010000100001000000000111111111110000
0000000000111111111111111111111111111111111111111111111111111111111111111111111111111111111111110000
0000000000100000000000000000001000000000000000000010000000000000010000100001000000000111111111110000
0000000000100000000000000000001000000000000000000010000000000000010000100001000000000111111111110000
0000000000100000000000000000001000000000000000000010000000000000011000100011000000000111111111110000
0000000000100000000000000000001000000000000000000010000000000000001100100110000000000011111111100000
0000000000100000000000000000001000000000000000000010000000000000000111111100000000000001111111000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000111111100000000000001111111000000
0000000000100000000000000000001000000000000000000010000000000000001111111110000000000011001001100000
0000000000100000000000000000001000000000000000000010000000000000011111111111000000000110001000110000
0000000000100000000000000000001000000000000000000010000000000000011111111111000000000100001000010000
0000000000100000000000000000001000000000000000000010000000000000011111111111000000000100001000010000
0000000000111111111111111111111111111111111111111111111111111111111111111111111111111111111000010000
0000000000100000000000000000001000000000000000000010000000000000011111111111000000000100001000010000
0000000000100000000000000000001000000000000000000010000000000000011111111111000000000100001000010000
0000000000100000000000000000001000000000000000000010000000000000011111111111000000000110001000110000
0000000000100000000000000000001000000000000000000010000000000000001111111110000000000011001001100000
0000000000100000000000000000001000000000000000000010000000000000000111111100000000000001111111000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000
0000000000111111111111111111111111111111111111111111111111111111111111111111111111111111111000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
Click to add a cell.
import numpy as np
import tensorflow as tf
# 给定的棋盘图像数据
import numpy as np
X_train = np.array([
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
])
# 对应的标签 (将围棋位置编码)
y_train = np.array([
[0, 0, 0, 0],
[0, 0, 1, 0],
[0, 2, 0, 0],
[0, 1, 2, 0],
[0, 0, 0, 0]
])
# 转换输入数据的形状以匹配模型要求
X_train = X_train.reshape((-1, 40, 50, 1))
# 输出标签需要转换为独热编码
y_train = tf.keras.utils.to_categorical(y_train, num_classes=20)
# 打印 X_train 和 y_train 的形状
print(X_train.shape)
print(y_train.shape)