저는 블렌더의 곡선에서 숫자를 예측하는 코드를 작성하려고합니다. 그래서 sklearn 사용과 같은 행렬로 곡선을 변환하고 불행히도 예측을 할 때마다 예측을 시도했습니다.sklearn은 숫자를 예측할 때 항상 1을 예측합니다.
2 차원 행렬 (내가 가지고있는 원처럼 보입니다. 믹서기) :
[[ 0. 0. 0. 0. 0. 0. 0. 0.]
[ 0. 0. 0. 25. 25. 0. 0. 0.]
[ 0. 25. 25. 25. 0. 25. 25. 0.]
[ 0. 25. 0. 0. 0. 0. 25. 0.]
[ 0. 25. 0. 0. 0. 0. 25. 0.]
[ 0. 25. 0. 0. 0. 0. 25. 0.]
[ 0. 0. 25. 25. 25. 25. 0. 0.]
[ 0. 0. 0. 0. 0. 0. 0. 0.]]
코드 :
import bpy
import numpy as np
from sklearn import datasets
from sklearn import svm
import scipy.misc
ob = bpy.context.object
assert ob.type == 'CURVE' # throw error if it's not a curve
curve = ob.data
spline = curve.splines.active # let's assume there's only one
assert spline.type == 'BEZIER' # throw error if it's not a bezier
shortest = None
shortestDist = 10000
shortest_x = None
shortestDist_x = 10000
result = []
for point in spline.bezier_points:
dist = point.co.y
dist_x = point.co.x
if dist < shortestDist : #test if better so far
shortest = point
shortestDist = dist
if dist_x < shortestDist_x : #test if better so far
shortest_x = point
shortestDist_x = dist
print(1/abs(shortest.co.y))
result.append([shortest, shortestDist, dist, dist_x])
mult_y = 1/abs(shortest.co.y)
mult_x = 1/abs(shortest_x.co.x)
point_pos = []
for point in spline.bezier_points:
loc = point.co.y
loc_x = point.co.x
max_y = loc * mult_y
max_x = loc_x * mult_x
point_pos.append([loc, loc_x])
matrix = np.zeros((8, 8))
pixel = []
for index in enumerate(matrix):
matrix_to_co_y = 1/len(matrix) * index[0]
for index_y in enumerate(matrix[index[0]]):
matrix_to_co_x = 1/len(matrix) * index_y[0]
#print(matrix_to_co_y)
for point in point_pos:
if matrix_to_co_y > point[0] > matrix_to_co_y - 1/len(matrix):
if matrix_to_co_x > point[1] > matrix_to_co_x - 1/len(matrix):
pixel.append([index[0], index_y[0]])
for p in enumerate(pixel):
matrix[p[1][0]][p[1][1]] = 25
flat = np.ravel(matrix)
digits = datasets.load_digits()
clf = svm.SVC(gamma=0.001, C=100)
x,y = digits.data[:-1], digits.target[:-1]
clf.fit(x,y)
print('Prediction:',clf.predict([flat]))
print(matrix)
나는 내가 잘못 알고하지 않습니다. 도움이 필요하십니까
난 당신이 scikit 배우기 튜토리얼에서 봐 가지고 제안했다. 여기에 필기 숫자의 분류가 표시됩니다. http://scikit-learn.org/stable/tutorial/basic/tutorial.html#introduction Digits 데이터 세트와 동일한 형식으로 입력을받을 수 있다면 튜토리얼을 따라야합니다. point – KPLauritzen
@KPLauritzen 훈련 데이터의 행렬과 행렬이 동일하게 보입니다. –
'digits' 데이터 세트의 일부 입력을 예측하려고하면 어떻게 될까요? 또한,'np.ravel' 대신'np.reshape' 또는'np.flatten'을 사용할 수 있습니까? 난 당신이 이미지 매트릭스에서 행 대신에 열에서 평평한 벡터를 얻고 있다고 생각합니다 – KPLauritzen