반응형
나는 MNIST 데이터 세트를 가지고 있으며 pyplot을 사용하여 시각화하려고합니다. 데이터 세트는 cvs
형식이며 각 행은 784 픽셀의 이미지 하나입니다. 28 * 28 이미지 형식의 pyplot
또는 opencv
로 시각화하고 싶습니다. 직접 사용하려고합니다.
plt.imshow(X[2:],cmap =plt.cm.gray_r, interpolation = "nearest")
하지만 나는 작동하지 않습니까? 어떻게 접근해야할지에 대한 아이디어.
해결 방법
MNIST 데이터 세트를 사용할 수있는 형식 인이 형식의 CSV 파일이 있다고 가정합니다.
label, pixel_1_1, pixel_1_2, ...
Matplotlib와 OpenCV를 사용하여 Python에서 시각화하는 방법은 다음과 같습니다.
import numpy as np
import csv
import matplotlib.pyplot as plt
with open('mnist_test_10.csv', 'r') as csv_file:
for data in csv.reader(csv_file):
# The first column is the label
label = data[0]
# The rest of columns are pixels
pixels = data[1:]
# Make those columns into a array of 8-bits pixels
# This array will be of 1D with length 784
# The pixel intensity values are integers from 0 to 255
pixels = np.array(pixels, dtype='uint8')
# Reshape the array into 28 x 28 array (2-dimensional array)
pixels = pixels.reshape((28, 28))
# Plot
plt.title('Label is {label}'.format(label=label))
plt.imshow(pixels, cmap='gray')
plt.show()
break # This stops the loop, I just want to see one
dtype = 'uint8'
(부호없는 8 비트 정수)이고 28 x 28 모양 인 pixels
numpy 배열을 가져 와서 로 플로팅 할 수 있습니다. cv2.imshow ()
title = 'Label is {label}'.format(label=label)
cv2.imshow(title, pixels)
cv2.waitKey(0)
cv2.destroyAllWindows()
참조 페이지 https://stackoverflow.com/questions/37228371
반응형
'파이썬' 카테고리의 다른 글
파이썬 Pip - Fatal error in launcher: Unable to create process using '"' (0) | 2020.11.03 |
---|---|
파이썬 서버에서 지원하지 않는 SMTP AUTH 확장 (0) | 2020.11.03 |
파이썬 robots.txt에 의해 금지됨 : 스크래피 (0) | 2020.11.03 |
파이썬 Django에서 이메일 전송 테스트 (0) | 2020.11.03 |
파이썬 Titlecasing a string with exceptions (0) | 2020.11.03 |
댓글