Python枕头图像导入处理错误 - 尽管安装正确但无法处理

时间:2018-06-10 22:52:04

标签: python image-processing tensorflow tuples pillow

我使用pip安装枕安装枕头(使用Mac)。然后,我也尝试做conda激活tensorflow,conda安装枕头,但没有运气。我一直收到错误,

Vue.component('alert', {
    template: `
  <div class="alert alert-info" v-if="show">
    <slot></slot>
  </div>`,

  data() {
        return {
    show: true
    }
  },
  mounted() {
     // directive event
     this.$root.$on("alert:close", () => this.show = false);
  }
});

Vue.directive('alert-dismiss', {
   inserted: function(el, binding, vnode) {
    el.addEventListener("click", () => {
        vnode.context.$root.$emit("alert:close");
    });
   }
});

我认为这与我的图像文件有关(最初都是png,但我将它们转换为jpgs)。但是,它似乎并没有起作用。我试图将我的所有图像文件转换为形状的张量(N,224,224,3),其中N是数据集中图像的数量。

当我跑步时,train_files? (这应该是一个图像文件路径列表),其中一些实际上显示缺少扩展(其后面没有.jpg或.png)。看看:

"cannot identify image file %r" and raise ImportError('Could not import 
PIL.Image. '

似乎它让我的代码崩溃了。有谁知道如何解决这个问题?

事实证明,我的数据还包含保存图像的文件夹。这就是为什么它背后没有.jpg扩展名。

以下是我如何构建图像文件路径列表:

'birdImages/train/04.Osprey/.DS_Store',
'birdImages/train/01.Great_blue_heron/Great-Blue-Heron-3 
DChristian.jpg',
'birdImages/train/05.Red_tailed_hawk/Red-tailed Hawk 2 DChristian.jpg',
'birdImages/train/04.Osprey/Osprey Joanne.jpg',
'birdImages/train/04.Osprey/Osprey 2 LK.jpg',

然后,我正在跑步:

from keras.preprocessing import image                  
from tqdm import tqdm

def path_to_tensor(img_path):
# loads RGB image as PIL.Image.Image type
    img = image.load_img(img_path, target_size=(224, 224))
# convert PIL.Image.Image type to 3D tensor with shape (224, 224, 3)
    x = image.img_to_array(img)
    return np.expand_dims(x, axis=0)

def paths_to_tensor(img_paths):
    list_of_tensors = [path_to_tensor(img_path) for img_path in 
tqdm(img_paths)]
    return np.vstack(list_of_tensors)

我的数据安排如下:

from PIL import ImageFile                            
ImageFile.LOAD_TRUNCATED_IMAGES = True                 

# pre-process the data for Keras
train_tensors = paths_to_tensor(train_files).astype('float32')/255

我相信它正在获取实际文件夹的文件路径,这导致崩溃上方发布的代码。有谁知道为什么枕头这样做?

0 个答案:

没有答案