GithubHelp home page GithubHelp logo

tslgithub / image_class Goto Github PK

View Code? Open in Web Editor NEW
433.0 12.0 145.0 2.02 MB

基于keras集成多种图像分类模型: VGG16、VGG19、InceptionV3、Xception、MobileNet、AlexNet、LeNet、ZF_Net、ResNet18、ResNet34、ResNet50、ResNet_101、ResNet_152、DenseNet

Python 98.79% Shell 1.21%

image_class's Introduction

图像分类集成以下模型:ResNet18、ResNet34、ResNet50、ResNet101、ResNet152、VGG16、VGG19、InceptionV3、Xception、MobileNet、AlexNet、LeNet、ZF_Net、DenseNet、mnist_net、TSL16,在config.py里面选择使用哪种模型.

the project apply the following models:

  • VGG16
  • VGG19
  • InceptionV3
  • Xception
  • MobileNet
  • AlexNet
  • LeNet
  • ZF_Net
  • ResNet18
  • ResNet34
  • ResNet50
  • ResNet101
  • ResNet152
  • DenseNet(dismissed this time)
  • mnist_net
  • TSL16

train or test dataset

classes name contained in folder name

"training or testing dataset folder is:"

/path/classes1/cat*.jpg,

/path/classes2/dog*.jpg,

/path/classes3/people*.jpg,

/path/classes4/*.jpg,

  • Attentions ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
  • classes name must be contained in folder name

environment

My environment is based on

  • ubuntu16
  • cuda8 (cuda9.0)
  • tensorflow_gpu1.4 (tensorflow_gpu1.10 )
  • keras2.0.8
  • numpy
  • tqdm
  • opencv-python
  • scikit-learn

Install packages

  • pip3 install tensorflow_gpu==1.4
  • pip3 install keras==2.0.8
  • pip3 install numpy
  • pip3 install tqdm
  • pip3 install opencv-python
  • pip3 install scikit-learn

1.confirm config.py

  • choose model and change parameter in config.py

2.train or test dataset prepare

  • python3 mk_class_idx.py

3.train your model

  • Train sigle model : python3 train.py modelName
  • Train All model : run " sh trainAll.sh " to train all model (in ubuntu)
  • Tensorboard : take LeNet as example, run " tensorboard --logdir=./checkpoints/LeNet " to watch training with tensorboard

4.predict your model

  • predict model: python3 predict.py modelName classesName

5.result of mnist dataset(number 0~9)

Image text

Any Questions???

Author email: [email protected]

image_class's People

Contributors

tslgithub avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

image_class's Issues

loss和val_loss不更新

你好,感谢你提供的代码,我在跑VGG16,VGG19,AlexNet时都出现了结果不更新的情况,在ResNet50上结果正常,请问我该如何解决呢?
Epoch 1/10
12992/12992 [==============================] - 108s 8ms/step - loss: 1.7006 - acc: 0.8902 - val_loss: 1.6784 - val_acc: 0.8959

Epoch 00001: val_loss improved from inf to 1.67843, saving model to ./checkpoints/VGG19/VGG19.h5
Epoch 2/10
12992/12992 [==============================] - 100s 8ms/step - loss: 1.7046 - acc: 0.8942 - val_loss: 1.6784 - val_acc: 0.8959

Epoch 00002: val_loss did not improve from 1.67843
Epoch 3/10
12992/12992 [==============================] - 100s 8ms/step - loss: 1.7046 - acc: 0.8942 - val_loss: 1.6784 - val_acc: 0.8959

Epoch 00003: val_loss did not improve from 1.67843
Epoch 4/10
12992/12992 [==============================] - 100s 8ms/step - loss: 1.7046 - acc: 0.8942 - val_loss: 1.6784 - val_acc: 0.8959

Epoch 00004: val_loss did not improve from 1.67843
Epoch 5/10
12992/12992 [==============================] - 100s 8ms/step - loss: 1.7046 - acc: 0.8942 - val_loss: 1.6784 - val_acc: 0.8959

Epoch 00005: val_loss did not improve from 1.67843
Epoch 6/10
12992/12992 [==============================] - 100s 8ms/step - loss: 1.7046 - acc: 0.8942 - val_loss: 1.6784 - val_acc: 0.8959

Epoch 00006: val_loss did not improve from 1.67843

Epoch 00006: ReduceLROnPlateau reducing learning rate to 0.0004999999888241291.
Epoch 7/10
12992/12992 [==============================] - 98s 8ms/step - loss: 1.7046 - acc: 0.8942 - val_loss: 1.6784 - val_acc: 0.8959

Epoch 00007: val_loss did not improve from 1.67843
Epoch 8/10
12992/12992 [==============================] - 99s 8ms/step - loss: 1.7046 - acc: 0.8942 - val_loss: 1.6784 - val_acc: 0.8959

Epoch 00008: val_loss did not improve from 1.67843
Epoch 9/10
12992/12992 [==============================] - 100s 8ms/step - loss: 1.7046 - acc: 0.8942 - val_loss: 1.6784 - val_acc: 0.8959

Epoch 00009: val_loss did not improve from 1.67843
Epoch 10/10
12992/12992 [==============================] - 100s 8ms/step - loss: 1.7046 - acc: 0.8942 - val_loss: 1.6784 - val_acc: 0.8959

Epoch 00010: val_loss did not improve from 1.67843

VGG16,显存溢出问题

config文件里面,我设置了参数batch_size = 32,normal_size = 224,然后使用VGG16之后,显存直接溢出了。训练集共3400多张图片,按说不至于吧。

我尝试了使用CPU + 内存运行,我显存8G,内存32G,想看下实际模型占用需要多少内存,结果一个batch之后,内存占用竟然达到31.1G。全部加载完图片大概是10G内存占用,也就是说中间21.1G是模型的。

我想确认下,请问up你有遇到过这个情况吗?或者有比较好的解释和解决方案吗?

训练时报错:AttributeError: 'NoneType' object has no attribute 'shape'

训练时,报下面的错误,请问怎么解决?

Traceback (most recent call last):
File "train.py", line 174, in
main()
File "train.py", line 170, in main
train.start_train()
File "train.py", line 148, in start_train
X_train, X_test, y_train, y_test=self.load_data()
File "train.py", line 55, in load_data
_, w, h = img.shape[::-1]
AttributeError: 'NoneType' object has no attribute 'shape'

why channles=1?

Channles = 1 is a gray level image. Wouldn't it be better to use color image to extract features?

模型

这些模型从哪里下载?没有提供下载链接?

关于损失函数与评价函数的选择是否不匹配?

您好,模型的编译阶段代码:model.compile(loss="categorical_crossentropy", optimizer=adam, metrics=["accuracy"]) 。
损失函数选取了"categorical_crossentropy",而评价函数选取了"accuracy",个人查看了一下keras中文文档,觉得accuracy处也应该选取“categorical_accuracy''。
image
因为,文章中用了与"categorical_crossentropy"配合使用的“to_categorical''函数,将每个类别对应的真值label转化成了如上图所示 :其中向量只有一个索引为1,其余索引为0,对应一个类别。而网络预测结果最后以softmax作为输出。所以我认为应该用“categorical_accuracy'',请问您是怎么考虑的关于“accuracy‘’,现在keras中文文档没有它的官方说明......也是比较神奇

MobileNet version

what is the MobileNet version? MobileNetV1? MobileNetV2? MobileNetV3?

关于predict.py的问题

我用自己的dataset做了训练也在config和predict中做了相应的路径和class修改,但是运行predict后会提示我下面这个错误
FileNotFoundError: [Errno 2] No such file or directory: './test/abnormal '
我明明这个路径下是有文件的,一开始我以为是单一文件,但是发现你提供的试验用打dataset中也是不只一张图,我想请问我该如何解决这个问题?

checkpoint问题

您好,首先很感谢您的repo对我的学习给予帮助
但是在运行过程中遇到了checkpoint的问题,以下是运行repo源程序的train.py训练中发生的错误:
……
ls: cannot access 'checkpoints/ResNet152/events*': No such file or directory
512
rm: cannot remove 'checkpoints/ResNet152/events*': No such file or directory
……
并在上一步产生错误后,用predict.py测试结果时,发生的错误:
OSError: Unable to open file (unable to open file: name = './checkpoints/VGG16/VGG16.h5', errno = 2, error message = 'No such file or directory', flags = 0, o_flags = 0)

try problem

ValueError: invalid literal for int() with base 10

VGG16

At first , thank you for providing a complete code.
When i use the VGG16 model,I got this result I think it might be wrong. But why?

90/90 [======] - 34s - loss: 7.9056 - acc: 0.5050 - val_loss: 8.3008 - val_acc: 0.4850om inf to 8.30082, saving model to ./checkpoints/VGG16/VGG16.h5
Epoch 2/300
90/90 [======] - 24s - loss: 7.9785 - acc: 0.5050 - val_loss: 8.3008 - val_acc: 0.4850rove
Epoch 3/300
90/90 [======] - 23s - loss: 7.9785 - acc: 0.5050 - val_loss: 8.3008 - val_acc: 0.4850rove
Epoch 4/300
90/90 [======] - 22s - loss: 7.9785 - acc: 0.5050 - val_loss: 8.3008 - val_acc: 0.4850rove
Epoch 5/300
89/90 [=====>.] - ETA: 0s - loss: 7.9866 - acc: 0.5045Epoch 00004: val_loss did not improve

90/90 [======] - 22s - loss: 7.9785 - acc: 0.5050 - val_loss: 8.3008 - val_acc: 0.4850
Epoch 6/300
90/90 [======] - 21s - loss: 7.9785 - acc: 0.5050 - val_loss: 8.3008 - val_acc: 0.4850rove
Epoch 7/300
90/90 [======] - 21s - loss: 7.9785 - acc: 0.5050 - val_loss: 8.3008 - val_acc: 0.4850rove
Epoch 8/300
89/90 [====>.] - ETA: 0s - loss: 7.9685 - acc: 0.5056Epoch 00007: val_loss did not improve

90/90 [======] - 21s - loss: 7.9785 - acc: 0.5050 - val_loss: 8.3008 - val_acc: 0.4850
Epoch 9/300
90/90 [======] - 21s - loss: 7.9785 - acc: 0.5050 - val_loss: 8.3008 - val_acc: 0.4850rove
Epoch 10/300
90/90 [======] - 21s - loss: 7.9785 - acc: 0.5050 - val_loss: 8.3008 - val_acc: 0.4850rove
Epoch 11/300
89/90 [====>.] - ETA: 0s - loss: 7.9866 - acc: 0.5045Epoch 00010: val_loss did not improve

90/90 [=====] - 21s - loss: 7.9785 - acc: 0.5050 - val_loss: 8.3008 - val_acc: 0.4850
Epoch 12/300
90/90 [=====] - 20s - loss: 7.9785 - acc: 0.5050 - val_loss: 8.3008 - val_acc: 0.4850rove
Epoch 00011: early stopping
Done

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.