legolas123 / cv-tricks.com Goto Github PK
View Code? Open in Web Editor NEWRepository for all the tutorials and codes shared at cv-tricks.com
License: MIT License
Repository for all the tutorials and codes shared at cv-tricks.com
License: MIT License
Hello,
Thank you for sharing this excellent work. I am trying to port the Crop Layer to cpp.
I am not very familiar with Python, can you elaborate on the meaning of this Python operation :
return [inputs[0][:,:,self.ystart:self.yend,self.xstart:self.xend]]
Is inputs[0]
a 4D cube and I want to take only the sub-cube delimited by x and y indexes?
Cheers,
Renaud
Hi Ankit,
I am new to image classification. I cloned your repository and tried to run the code train.py in my system. I just keep getting an error message saying:
"2018-06-17 00:19:55.817737: W tensorflow/core/framework/op_kernel.cc:1318] OP_REQUIRES failed at save_restore_v2_ops.cc:109 : Not found: ; No such file or directory
Traceback (most recent call last):
File "train.py", line 206, in
train(num_iteration=3000)
File "train.py", line 201, in train
saver.save(session, 'dogs-cats-model')
File "/Users/z001txn/anaconda/lib/python2.7/site-packages/tensorflow/python/training/saver.py", line 1720, in save
raise exc
ValueError: Parent directory of dogs-cats-model doesn't exist, can't save."
I think the problem is in saving the model but I am not able to figure out how to solve it. Can you please help me out here.
Thanks,
Aishwarya
i have built a cnn network which im trying to train with my own data. but when i run the code i get the next error:
File "C:/linear regression/new_net.py", line 92, in <module>
ValueError: Cannot feed value of shape (500, 99999) for Tensor 'X:0', which has shape '(500, 4392)'
and i dont know what value i need to fix. my data is built of 100,000 rows on 4392 column. i reshape each row to 61*72 pixels which means i have 100,000 images. i take 80,000 to the training and 20,000 to the test. and using batch size of 500. i dont know what is wrong with the code if someone can help please!!!
here is my code:
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import csv
import time
import os
import urllib
import numpy as np
import tensorflow as tf
#input images- chek if i need the transpose command
data_in = np.transpose(np.loadtxt(open("images.csv"), delimiter=","))
images_training="images.csv"
train_X=data_in[0:80000,:]
test_X=data_in[80001:100000,:]
test_images=test_X[:,1]
test_labels=test_X[:,0]
n = train_X.shape[1]
l = test_X.shape[0]
n_epochs = 10
batch_size = 500
regions=50
height = 61
width = 72
channels = 1
n_inputs = height * width #4392
X = tf.placeholder(tf.float32, shape=[batch_size, n_inputs], name="X")
X_reshaped = tf.reshape(X, shape=[-1, height, width, channels])
y = tf.placeholder(tf.int32, shape=[None], name="y")
labels=tf.placeholder(tf.int32, shape=[batch_size], name="labels")
conv1 = tf.layers.conv2d(inputs=X_reshaped,filters=32,kernel_size=[5,
5],padding="same",activation=tf.nn.relu)
pool1 = tf.layers.max_pooling2d(inputs=conv1, pool_size=[2, 2], strides=2)
#need to change pool size and strides according to image pixels
conv2 = tf.layers.conv2d(inputs=pool1,filters=64,kernel_size=[5,
5],padding="same",activation=tf.nn.relu)
pool2 = tf.layers.max_pooling2d(inputs=conv2, pool_size=[2, 2],
strides=2)#need to change pool size and strides according to image pixels
pool2_flat = tf.reshape(pool2, [-1, 15 * 18 * 64]) #change it according to
the pooling layers size:[batch_size,18432]
dense = tf.layers.dense(inputs=pool2_flat, units=1024,
activation=tf.nn.relu)
# Add dropout operation; 0.6 probability that element will be kept
dropout = tf.layers.dropout(inputs=dense, rate=0.4)
# Logits layer
# Input Tensor Shape: [batch_size, 1024]
# Output Tensor Shape: [batch_size, 50]
logits = tf.layers.dense(inputs=dropout, units=50) #size=[batch_size,50]
predictions = {
# Generate predictions (for PREDICT and EVAL mode)
"classes": tf.argmax(input=logits, axis=1),
# Add `sigmoid_tensor` to the graph. It is used for PREDICT and by the
# `logging_hook`.
"probabilities": tf.nn.sigmoid(logits, name="sigmoid_tensor")}
onehot_labels = tf.one_hot(indices=tf.cast(labels, tf.int32), depth=50)
#loss = tf.losses.sigmoid_cross_entropy(multi_class_labels=labels,
logits=logits)
loss = tf.losses.sigmoid_cross_entropy(onehot_labels, logits=logits)
optimizer = tf.train.GradientDescentOptimizer(learning_rate=0.001)
train_op = optimizer.minimize(loss=loss,
global_step=tf.train.get_global_step())
# Initializing the variables
init = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
for epoch in range(n_epochs):
for iteration in range(len(train_X) // batch_size):
# this cycle is for dividing step by step the heavy work of each neuron
X_batch = train_X[iteration * batch_size:iteration * batch_size + batch_size, 1:]
y_batch = train_X[iteration * batch_size:iteration * batch_size + batch_size, 0]
sess.run(optimizer,feed_dict={X:X_batch, y:y_batch})
sess.run(train_op, feed_dict={X: X_batch, y: y_batch})
acc_train =accuracy.eval(feed_dict={X: X_batch, y: y_batch})
acc_test =accuracy.eval(feed_dict={X: test_images, y: test_labels})
print("Epoch:", epoch + 1, "Train accuracy:", acc_train, "test accuracy:", acc_test)
print("Optimization Finished!")
in addition i dont understand why python takes my data as 99,999 and not 100,000.
thank you!!!
I did the training, it had 95% confidence.
Somehow my prediction is always the same, even when giving a different image to test (changing cats to dogs):
[[0.5592177 0.44078225]]
[[0.5690457 0.43095428]]
Anyway to debug or help out what is going wrong?
I am getting the below outputs for Cat and Dog images respectively. how do i interpret it?
run : python predict.py testing_data/cats/cat.1041.jpg
output: [[3.3456912e-05 9.9996650e-01]]
run: python predict.py testing_data/dogs/dog.1000.jpg
output: [[5.817143e-05 9.999418e-01]]
Hi,
I am getting the following error when using code from your repository for Image classifier CNN:
Traceback (most recent call last):
File "E:/Machine Learning/TensorFlow/Tutorials & Practice/CV Tricks/train.py", line 292, in <module>
optimize(num_iterations=3000)
File "E:/Machine Learning/TensorFlow/Tutorials & Practice/CV Tricks/train.py", line 261, in optimize
x_batch, y_true_batch, _, cls_batch = data.train.next_batch(train_batch_size)
File "E:\Machine Learning\TensorFlow\Tutorials & Practice\CV Tricks\dataset.py", line 117, in next_batch
assert batch_size <= self._num_examples
AssertionError
I am not sure what am I missing, Can you help me please?
OS: Windows 10
IDE: Pycharm
Python: Python 3.5.2 :: Anaconda 4.1.1 (64-bit)
I run the code of image-classifier, it's a little slow in my laptop.
My computer:
Intel Core i7 6700-HQ
NVIDIA GeForce GTX960M
run in GPU
Then I try move the save code into the if rather than out of if
It become much faster.....
And I think it is useless to do so much save and waste time in IO
Maybe this would be helpful if you want to accelerate your code
Traceback (most recent call last):
File "edge.py", line 42, in <module>
cv.dnn_registerLayer('Crop', CropLayer)
AttributeError: module 'cv2.cv2' has no attribute 'dnn_registerLayer'
Hello,
I am trying to add data augmentation to increase the number of images I have to at least 2,000 images per class. How can I achieve this?
Any help will be really appreciated
Quantization code is never called since it is commented. Binary convolution and activation is already implemented. Do I need to uncomment them (a few of them are given below)? During the forward pass I always quantize the weights and activation. Why do I need "quantization.py" ?
# if args.quantize:
# global bin_op
# bin_op = quantization.Binarize(model)
# if args.quantize:
# bin_op.restore()
# bin_op.updateBinaryGradWeight()
if I uncomment them, I get the following error.
File "main2.py", line 88, in main
bin_op = quantization.Binarize(model)
File "/media/mmrg/inci/files/quantization.py", line 33, in __init__
param_grp_1.append(m.conv.weight)
File "/home/mmrg/anaconda3/envs/pytorch_mmdet/lib/python3.7/site-packages/torch/nn/modules/module.py", line 779, in __getattr__
type(self).__name__, name))
torch.nn.modules.module.ModuleAttributeError: 'BinConv2d' object has no attribute 'conv'
Where could I get the code for passing an image to a CNN Cifar10 TensorFlow Model and getting the result in terms of prediction scores
I had Build the CNN Cifar10 TensorFlow Model following the tutorial at
https://www.tensorflow.org/tutorials/deep_cnn
Code:
https://github.com/tensorflow/models/tree/master/tutorials/image/cifar10
Hi!
I get the following error when I want to run edge detection on an image. Any idea why I get that specific dnn layer error?
cv2.error: OpenCV(4.6.0) /io/opencv/modules/dnn/src/layers/convolution_layer.cpp:377: error: (-215:Assertion failed) !blobs.empty() || inputs.size() > 1 in function 'getMemoryShapes'
~/git/cv-tricks.com/Tensorflow-tutorials/tutorial-2-image-classifier$ python train.py --train training_data/ --val testing_data/ --num_classes 2
Going to read training images
Now going to read dogs files (Index: 0)
Now going to read cats files (Index: 1)
Complete reading input data. Will Now print a snippet of it
Number of files in Training-set: 800
Number of files in Validation-set: 200
WARNING:tensorflow:From train.py:44: calling argmax (from tensorflow.python.ops.math_ops) with dimension is deprecated and will be removed in a future version.
Instructions for updating:
Use the axis
argument instead
WARNING:tensorflow:From train.py:160: softmax_cross_entropy_with_logits (from tensorflow.python.ops.nn_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Future major versions of TensorFlow will allow gradients to flow
into the labels input on backprop by default.
See @{tf.nn.softmax_cross_entropy_with_logits_v2}.
Training Epoch 1 --- Training Accuracy: 50.0%, Validation Accuracy: 43.8%, Validation Loss: 0.705
2018-08-17 16:52:14.024307: W tensorflow/core/framework/op_kernel.cc:1275] OP_REQUIRES failed at save_restore_v2_ops.cc:109 : Not found: ; No such file or directory
Traceback (most recent call last):
File "train.py", line 206, in
train(num_iteration=3000)
File "train.py", line 201, in train
saver.save(session, 'dogs-cats-model')
File "/home/Wukong2/l00176142/.local/lib/python2.7/site-packages/tensorflow/python/training/saver.py", line 1637, in save
raise exc
ValueError: Parent directory of dogs-cats-model doesn't exist, can't save.
Hi,
I am getting error "frozen importlib._bootstrap>(219)_call_with_frames_removed()" after line 93.
93 line is class DataSets(object):
I am new in Deep Learning as well as in Tensorflow.
Please help to resolve this issue
Could you add a way to save the model?
Also, could you add a file to load the saved model and infer the prediction on a test image?
Laurent
In the folder, Tensorflow-tutorials/Tensorflow-slim-run-prediction when I run python run_inference_on_v3.py http://cv-tricks.com/wp-content/uploads/2017/03/pexels-photo-280207.jpeg
To run the prediction for the model inception_v3 as per the blog post http://cv-tricks.com/tensorflow-tutorial/understanding-alexnet-resnet-squeezenetand-running-on-tensorflow/, I get the following error:
TypeError: Expected int32, got list containing Tensors of type '_Message' instead.
Tensorflow version: 1.1
Getting an error while running the code.
python3 run_pose.py --input sample.jpg --proto pose/mpi/pose_deploy_linevec_faster_4_stages.prototxt --model pose/mpi/pose_iter_160000.caffemodel --dataset MPI
time is 2.5539000034332275
: cannot connect to X server
my issue is in imagnet.py where my tring to access url am getting the url error as follows
filename, _ = urllib.urlretrieve(synset_url,"imagenet_lsvrc_2015_synsets.txt")
File "/usr/lib/python2.7/urllib.py", line 94, in urlretrieve
return _urlopener.retrieve(url, filename, reporthook, data)
File "/usr/lib/python2.7/urllib.py", line 240, in retrieve
fp = self.open(url, data)
and my code is
base_url = 'https://github.com/tensorflow/models/tree/master/research/inception/inception/data'
synset_url = 'https://github.com/tensorflow/models/tree/master/research/inception/inception/data/imagenet_lsvrc_2015_synsets.txt'.format(base_url)
synset_to_human_url = 'https://github.com/tensorflow/models/tree/master/research/inception/inception/data/imagenet_metadata.txt'.format(base_url)
filename, _ = urllib.urlretrieve(synset_url,"imagenet_lsvrc_2015_synsets.txt")
synset_list = [s.strip() for s in open(filename).readlines()]
num_synsets_in_ilsvrc = len(synset_list)
assert num_synsets_in_ilsvrc == 1000
filename, _ = urllib.urlretrieve(synset_to_human_url,"imagenet_metadata.txt")
synset_to_human_list = open(filename).readlines()
num_synsets_in_all_imagenet = len(synset_to_human_list)
assert num_synsets_in_all_imagenet == 21842
please help me am totally frustraed bu this issue
I am not able to get the image_path correctly.
The output is showing ---------------------list index out of range by running your code predict.py
dir_path = os.path.dirname(os.path.abspath(__file__)) image_path=sys.argv[1]
due to which image = cv2.resize(image, (image_size, image_size),0,0, cv2.INTER_LINEAR)
is also not working.
output of dir_path D:\WORKSPACE\Deep_learning\others\cv_tricks.com_new\cv-tricks.com\Tensorflow-tutorials\tutorial-2-image-classifier
output of image_path D:/WORKSPACE/Deep_learning/others/cv_tricks.com_new/cv-tricks.com/Tensorflow-tutorials/tutorial-2-image-classifier/predict.py
how can this be solved?
WARNING:tensorflow:From train.py:43: calling argmax (from tensorflow.python.ops.math_ops) with dimension is deprecated and will be removed in a future version.
Instructions for updating:
Use the axis
argument instead
WARNING:tensorflow:From train.py:156: calling argmax (from tensorflow.python.ops.math_ops) with dimension is deprecated and will be removed in a future version.
Instructions for updating:
Use the axis
argument instead
Going to read training images
Now going to read dogs files (Index: 0)
Now going to read cats files (Index: 1)
Complete reading input data. Will Now print a snippet of it
Number of files in Training-set: 800
Number of files in Validation-set: 200
Training Epoch 1 --- Training Accuracy: 50.0%, Validation Accuracy: 43.8%, Validation Loss: 0.703
Traceback (most recent call last):
File "C:\Users\USER\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\client\session.py", line 1327, in _do_call
return fn(*args)
File "C:\Users\USER\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\client\session.py", line 1306, in _run_fn
status, run_metadata)
File "C:\Users\USER\AppData\Local\Programs\Python\Python36\lib\contextlib.py", line 89, in exit
next(self.gen)
File "C:\Users\USER\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\errors_impl.py", line 466, in raise_exception_on_not_ok_status
pywrap_tensorflow.TF_GetCode(status))
tensorflow.python.framework.errors_impl.NotFoundError: Failed to create a directory:
[[Node: save/SaveV2 = SaveV2[dtypes=[DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT], _device="/job:localhost/replica:0/task:0/cpu:0"](_arg_save/Const_0_0, save/SaveV2/tensor_names, save/SaveV2/shape_and_slices, Variable, Variable/Adam, Variable/Adam_1, Variable_1, Variable_1/Adam, Variable_1/Adam_1, Variable_2, Variable_2/Adam, Variable_2/Adam_1, Variable_3, Variable_3/Adam, Variable_3/Adam_1, Variable_4, Variable_4/Adam, Variable_4/Adam_1, Variable_5, Variable_5/Adam, Variable_5/Adam_1, Variable_6, Variable_6/Adam, Variable_6/Adam_1, Variable_7, Variable_7/Adam, Variable_7/Adam_1, Variable_8, Variable_8/Adam, Variable_8/Adam_1, Variable_9, Variable_9/Adam, Variable_9/Adam_1, beta1_power, beta2_power)]]
Hi,
Thanks for putting this up on github. It got me started with tensorflow.
However some comments;
I think the dataset shows a lot of underfitting. I get a validation score of 0.5 at end, or even below.
I connected tensorboard and the learning graph shows classic underfitting signs (straight learning rate).
Perhaps it doesn't help that the images have wide ranging aspect ratios?
I tried to insert horizontal flipped images as well, but it doesn't help that much.
Hi!
In predict.py I am always getting the same output even though the image are of cats(for example ), the probability is very less for that image.
What is the meaning of "Using real valued downsample"?
is there a edge detection model which is not in caffe ?
as caffe merged into pytorch, it's almost not used anymore. instaling caffe "just for that" is too bad.
I'm running 2.2.4..
File "./1_vgg16_pretrain.py", line 1, in <module>
from network import VGG16
ModuleNotFoundError: No module named 'network'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.