Finetune a Caffe model in Torch - machine-learning

I want to finetune a neural net that has been pretrained. However, this model was made in Caffe and I would like to work in Torch.
I have tried loadcaffe, but this does not seem focused on finetuning.
Is there another tool that makes this possible? Or can the Caffe model be converted to a Torch net?

All you need to do is
use loadcaffe to convert your Caffe pretrained network into a Torch version.
(right after you can save it on disk with torch.save("net.t7", model))
write Torch code to fine-tune it.

Related

How to extract weights from trained tensorflow object detection api model

I am using the Tensorflow Object Detection API to train a couple of models (with SSD and Faster RCNN) in a custom dataset. Everything works well, but I want to know how to extract the convolutional and classification model weights, in order to load those weights in an external (for instance keras) convolutional and full connected corresponding model. I've read about the meta architectures (SSDMetaArch and FasterRCNNMetaArch) and restoring checkpoint, but I am not sure yet how to do it for my purpose.
The above because I want to use something like CAM or GradCAM to visually check what the model learns for every class in my dataset.
Thank you

Image classification, narrow domain with custom labels

Let's suppose I would like to classify motorbikes by model.
there are couple of hundreds models of motorbikes I'm interested in.
I do have tens, sometimes hundreds of pictures of each motorbike model.
Can you please point me to the practical example that demonstrates how to train model on your data and then use it to classify images? It needs to be a deep learning model, not simple logistic regression.
I'm not sure about it, but it seems like I can't use pre-trained neural net because it has been trained on wide range of objects like cat, human, cars etc. They may be not too good at distinguishing the motorbike nuances I'm interested in.
I found couple of such examples (tensorflow has one), but sadly, all of them were using pre-trained model. None of it had example how to train it on your own dataset.
In cases like yours you either use transfer learning or fine tuning. If you have more then thousand images of motorbikes I would use fine tuning and if you have less transfer learning.
Fine tuning is using a pre trained model and using a different classifier part. Then the new classifier part maybe the last 1-2 layers of the trained model are trained to your dataset.
Transfer learning means using a pre trained model and letting it output features for an input image. Now you use a new classifier based on those features. Maybe a SVM or a logistic regression.
An example for this can be seen here: https://github.com/cpra/dlvc2016/blob/master/lectures/lecture10.pdf. slide 33.
This paper Quick, Draw! Doodle Recognition from a kaggle challenge may be similar enough to what you are doing. The code is on github. You may need some data augmentation if you only have a few hundred images for each category.
What you want is pretty EZ. Follow the darknet YOLO implementation
Instruction: https://pjreddie.com/darknet/yolo/
Code https://github.com/pjreddie/darknet
Training YOLO on COCO
You can train YOLO from scratch if you want to play with different training regimes, hyper-parameters, or datasets. Here's how to get it working on the COCO dataset.
Get The COCO Data
To train YOLO you will need all of the COCO data and labels. The script scripts/get_coco_dataset.sh will do this for you. Figure out where you want to put the COCO data and download it, for example:
cp scripts/get_coco_dataset.sh data
cd data
bash get_coco_dataset.sh
Add your data inside and make sure it is same as testing samples.
Now you should have all the data and the labels generated for Darknet.
Then call training script with the pre-trained weight.
Keep in mind that only training on your motorcycle may not result in good estimation. There would be biased result coming out, I red it somewhere b4.
The rest is all inside the link. Good luck

How to convert (samesize, categoriezed) images into dataset for TensorFlow

I am learning to create a learning model using TensorFlow.
I have successfully run the MNIST tutorial, now would like to test the model with my own images. They are same-size image (224x224) and classified into folders.
Now I would like to use those images as input for my model as in the MNIST example. I tried to open the MNIST data-set but it's unreadable. I guess it has been converted into some binary types. Through the example, I think the MNIST dataset somehow has a structure like this:
mnist
test
images
labels
train
images
labels
How can I make a dataset look like the MNIST data from my own images files?
Thank you very much!
MNIST is not stored in image format. From the mnist web-site (http://yann.lecun.com/exdb/mnist/) you could see that it has specific format which is already close to the tensor or numpy array, which could be used in tensorflow with minimal adjustments. It is a kind of a matrix with numbers.
What you need to work with usual images (.jpg for instance) is to use any python lib for image processing to convert into the np.array. For example PIL will work, like here:
PIL and numpy
Another option is to use a built-in functions from tensorflow to convert your images straight to tensors supported by tensofrlow, check this out:
https://www.tensorflow.org/versions/r0.9/api_docs/python/image.html

OpenCV SVM: Update a trained SVM

I am using OpenCV 2.4.6 ( the only Version which is available on this PC).
So I have a SVM Modell with the default parameters which is already trained. Now I want to update it with new Samples.
CvSVM Support_VectorMachine;
Support_Vector_Machine.load(FilePath);
struct CvSVMParams Parameter;
Parameter = Support_Vector_Machine.get_params();
Support_Vector_Machine.train(TrainMatrix, Labels, cv::Mat(), cv::Mat(), Parameter);
So the Problem is, as mentioned in the OpenCV Statistical Models Dokumentation, that the train method calls the CvStatModel::clear() method, so my trained model gets overwritten.
Is there any solution or do I have to use a newer Version of open CV or another library for machine learning?
Thanks for your help.
SVM is not an online algorithm. This means that it doesn't support incremental learning which is what you are trying to do. So if you want to add new points you must retrain the model again.
There are some variations of SVM that support online learning (i.e Pegasos SVM), but I don't think OpenCV implement them.

how to use libsvm model file in opencv

I am developing an OCR using SVM in opencv C++. SVM used is (one vs one multi-class) linear SVM. Opencv svm (multi-class)doesn't give probability estimates for each class that was used in time of training. So i tried my luck with libsvm Multi-class classification (and probability output) via error-correcting codes. It gave me the probability estimates for each of the class, now I want to use the training model file in opencv C++. I get an error. Now my problem is how to use the training model in opencv, if not possible how to get probability estimates for each of the class using (one vs one multi-class) linear svm ?

Resources