哪些因素会影响tensorlayer.prepro.threading_data的返回类型?
I’ve dealt with this exact gotcha with tensorlayer.prepro.threading_data before—total head-scratcher at first!
The reason you’re seeing mixed return types (sometimes ndarray, sometimes a list) boils down to shape inconsistencies in your input list. In your scenario, some of your PNGs were 3-channel RGB images, while others were 4-channel RGBA (with an alpha channel).
Here’s the breakdown: when every element in your input has the exact same shape, threading_data can stack them into a single, contiguous ndarray without issues. But if even one element has a mismatched shape (like different channel counts here), it can't perform that stacking operation uniformly. Instead, it just returns a list of the individual arrays since they can't be combined into a single tensor-like structure.
The fix is simple: remove the alpha channel (the 4th channel) from all your PNG images. Once all your input elements share identical shapes, threading_data will consistently spit out an ndarray as you’d expect.
内容的提问来源于stack exchange,提问作者TheTomer

