In this paper, we propose an effective retraining method for optimizing the Convolutional Neural Network (CNN) features towards Content Based Image Retrieval (CBIR). To accomplish this goal, we utilize a pretrained CNN model, and we adapt it to a lightweight fully convolutional model which allows for producing compact image representations, reducing the storage requirements. Subsequently, we obtain the feature representations of the last convolutional layer using the max pooling operation, and we retrain the weights of the convolutional layers in a fully unsupervised fashion, aiming to produce more efficient compact image descriptors which improve the retrieval performance both in terms of time and precision. The experimental validation on three publicly available image retrieval datasets indicates the effectiveness of the proposed method in learning more efficient representations for the retrieval task, accomplishing significantly enhanced performance in all the used datasets.