Quantiphi Interview Question

Explain conv1D operation over an image

Interview Answer

Anonymous

Mar 13, 2025

Applying Conv1D to an Image An image is a 2D structure with shape ( β„Ž 𝑒 𝑖 𝑔 β„Ž 𝑑 , 𝑀 𝑖 𝑑 𝑑 β„Ž , 𝑐 β„Ž π‘Ž 𝑛 𝑛 𝑒 𝑙 𝑠 ) (height,width,channels). Applying Conv1D to an image means treating the width (columns) as a sequence while ignoring the height. This is typically done in two ways: Case 1: Conv1D Along the Width (Common Approach) The input image has shape ( β„Ž 𝑒 𝑖 𝑔 β„Ž 𝑑 , 𝑀 𝑖 𝑑 𝑑 β„Ž , 𝑐 β„Ž π‘Ž 𝑛 𝑛 𝑒 𝑙 𝑠 ) (height,width,channels). The Conv1D kernel moves along the width (columns). This extracts features along horizontal structures. Output shape: ( β„Ž 𝑒 𝑖 𝑔 β„Ž 𝑑 , 𝑛 𝑒 𝑀 _ 𝑀 𝑖 𝑑 𝑑 β„Ž , 𝑓 𝑖 𝑙 𝑑 𝑒 π‘Ÿ 𝑠 ) (height,new_width,filters). Case 2: Conv1D Along the Height (Alternative Approach) We can reshape the image so that height is treated as width: ( 𝑀 𝑖 𝑑 𝑑 β„Ž , β„Ž 𝑒 𝑖 𝑔 β„Ž 𝑑 , 𝑐 β„Ž π‘Ž 𝑛 𝑛 𝑒 𝑙 𝑠 ) (width,height,channels). The Conv1D kernel slides vertically across the height. Output shape: ( 𝑀 𝑖 𝑑 𝑑 β„Ž , 𝑛 𝑒 𝑀 _ β„Ž 𝑒 𝑖 𝑔 β„Ž 𝑑 , 𝑓 𝑖 𝑙 𝑑 𝑒 π‘Ÿ 𝑠 ) (width,new_height,filters).