简体   繁体   English

如何将我的 csv 文件像素数据转换为图像

[英]How Can I convert my csv files pixel data into image

I am totally beginner in this field.我完全是这个领域的初学者。 I started working with neural network for image classification purpose.我开始使用神经网络进行图像分类。 My question is I loaded one row through panda.我的问题是我通过熊猫加载了一行。 now I want to see that image like from which category it is.现在我想看看它属于哪个类别的图像。 it has label 0. so how i can convert that pixels values into image.它有 label 0。所以我如何将像素值转换为图像。

import matplotlib.pyplot as plt
import tensorflow as tf
import numpy as np
import pandas as pd
import seaborn as sns
import cv2
import os

#import deep learning libraries
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.preprocessing import image

df = pd.read_csv(r"/content/drive/MyDrive/Colab Notebooks/fe/icml_face_data.csv", nrows = 1)
df.pixel

0    70 80 82 72 58 58 60 63 54 58 60 48 89 115 121...
Name: pixel, dtype: object

The above pixel values I am getting now in next step I want to convert this into image.我现在在下一步中获得的上述像素值我想将其转换为图像。

You can visualise an image using matplotlib ( plt.imshow ) or seaborn ( sns.heatmap ).您可以使用 matplotlib ( plt.imshow ) 或 seaborn ( sns.heatmap ) 可视化图像。 Note that in all cases you'll probably want to change the colour map to something other than the default.请注意,在所有情况下,您可能都希望 将颜色 map 更改为默认值以外的颜色。

However, it looks like your image is stored in a vector, not a 2D matrix.但是,看起来您的图像存储在向量中,而不是二维矩阵中。 You can reshape this using numpy ( np.reshape ) but you will need to know the original dimensions of your image for this transformation.您可以使用 numpy ( np.reshape ) 对其进行整形,但您需要知道此转换的图像的原始尺寸。 You can use df.pixel.to_numpy() to make a numpy vector.您可以使用df.pixel.to_numpy()制作 numpy 向量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM