如何通过展平张量对多个图像进行 PCA?
我有一系列图像的张量。我想将矢量弄平并在相同的情况下执行PCA。
以下是在单个图像上提取张量的代码:
bottle_neck_model_tensors = bottle_neck_model([im_resize])[0]
bottle_neck_model_tensors
我想在多个图像上执行相同的操作,并且也将阵列弄平。后来在数组上执行PCA。
谁能帮我吗?
多个图像的代码,
import glob
import cv2 as cv
path = glob.glob(".../SampleImages*.jpg")
cv_img = []
for img in path:
n = cv.imread(img)
#print(n.shape)
im_resize = cv2.resize(n , (1024 ,1024))
im_resize = np.expand_dims(im_resize, axis = 0)
cv_img.append(im_resize)
bottle_neck_model_tensors = bottle_neck_model([im_resize])[0]
我想即兴创作此代码并使向量变平。我之所以重塑,是因为我从提取的层创建的模型是形状(无,128、128、512)
,而对模型的输入映像为1024,1024,3
。
I have an array of tensors for a single image. I want to flatten the vectors and perform PCA on the same.
The below is the code to extract the tensors on a single image :
bottle_neck_model_tensors = bottle_neck_model([im_resize])[0]
bottle_neck_model_tensors
I want to do the same on multiple images and also flatten the array. later perform PCA on the array.
Can anyone help me with this?
Code For multiple images
import glob
import cv2 as cv
path = glob.glob(".../SampleImages*.jpg")
cv_img = []
for img in path:
n = cv.imread(img)
#print(n.shape)
im_resize = cv2.resize(n , (1024 ,1024))
im_resize = np.expand_dims(im_resize, axis = 0)
cv_img.append(im_resize)
bottle_neck_model_tensors = bottle_neck_model([im_resize])[0]
I want to improvise this code and flatten the vectors. I am reshaping because the model I created from the extracted layers is of shape ( None, 128, 128, 512)
and the input image to the model is 1024, 1024, 3
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论