In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
How to compare the Keras vs PyTorch framework, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.
In the comparison between Keras and PyTorch, the author also gives the benchmark test results of the performance of the same neural network in different frameworks. Currently, Keras has more than 31000 Stars on GitHub, while PyTorch, which appears later, has nearly 17000 Stars.
It is worth mentioning that although PyTorch added support for Windows in version 0.4 at the end of April, there is still a slight gap in the stability of Keras and TensorFlow on Windows.
Links to the two major frames:
Keras: https://github.com/keras-team/keras (https://keras.io/)
PyTorch: https://github.com/pytorch/pytorch
Do you want to learn deep learning? Do you want to apply deep learning to the business, or to develop a sideline with deep learning, or just to acquire skills that meet the needs of the market? No matter what the goal is, choosing the appropriate deep learning framework is the first step to achieving the goal.
We strongly recommend that you choose Keras or PyTorch. They are very powerful tools, and both learning and experimenting are fun. We consider it from the point of view of teachers and students. Piotr has held Keras and PyTorch seminars in enterprises, Rafa? Are learning these two frameworks.
I. brief introduction
Keras and PyTorch are popular open source frameworks for deep learning among data scientists.
Keras is an advanced API (or as a tf.contrib within TensorFlow) that can run on TensorFlow, CNTK, Theano, or MXNet. Keras was first released in March 2015 and has grown rapidly since it was supported for its ease of use and grammatical simplicity. Keras is a framework supported by Google.
PyTorch, released in January 2017, is a lower-level API that focuses on working directly with array expressions. It received a lot of attention last year as a solution for academic research and deep learning applications that need to optimize custom expressions. It is a framework supported by Facebook.
Before we discuss the details of the two, we would like to make it clear that we do not have a direct answer to the question of which framework is better. Which framework you choose ultimately depends on your technical background, needs, and expectations. This article is designed to help you better understand when to choose Keras or PyTorch.
To sum up: Keras is easier to learn and experiment with the standard layer, plug and play; PyTorch provides a lower-level approach that is more flexible for users with a more mathematical background.
Second, why not use other frameworks?
This article does not discuss the advantages and disadvantages of choosing TensorFlow as the preferred deep learning framework, because we think that TensorFlow is less friendly to beginners than Keras (the official high-level library of TensorFlow) and PyTorch. Although you can find some Theano tutorials, it is no longer active in development. Caffe lacks flexibility, and Torch uses the Lua language (however, its rewriting is very difficult:). MXNet, Chainer and CNTK are not so widely used at present.
III. Keras vs PyTorch: ease of use and flexibility
Keras and PyTorch run at different levels of abstraction.
Keras is a higher-level framework that encapsulates commonly used deep learning layers and operations into clean Lego-sized building blocks so that data scientists no longer have to think about the complexity of deep learning.
PyTorch provides a relatively low-level experimental environment that allows users to write custom layers and view numerical optimization tasks more freely. When you can use the full power of Python to access the core of all the functions used, the development of complex architectures is more straightforward. This will naturally come at the expense of tediousness.
The following is a comparison of the simple convolution networks defined in Keras and PyTorch:
1. Keras
Model = Sequential () model.add (Conv2D (32, (3,3), activation='relu', input_shape= (32,32,3)) model.add (MaxPool2D ()) model.add (Conv2D (16, (3,3), activation='relu')) model.add (MaxPool2D ()) model.add (Flatten ()) model.add (Dense (10, activation='softmax'))
2. PyTorch
Class Net (nn.Module): def _ init__ (self): super (Net, self). _ _ init__ () self.conv1 = nn.Conv2d (3,32,3) self.conv2 = nn.Conv2d (32,16,3) self.fc1 = nn.Linear (16 * 6 * 6,10) self.pool = nn.MaxPool2d (2,2) def forward (self X): X = self.pool (F.relu (self.conv1 (x) x = self.pool (F.relu (self.conv2 (x) xx = x.view (- 1,16 * 6 * 6) x = F.log_softmax (self.fc1 (x), dim=-1) return x model = Net ()
The above code snippet shows a slight difference between the two frameworks. As for model training, it requires about 20 lines of code in PyTorch and only one line in Keras. GPU acceleration can be handled implicitly in Keras, while PyTorch requires us to specify when to migrate data between CPU and GPU.
If you are a novice, then Keras as a higher-level framework may have a clear advantage. Keras is indeed more readable and concise, allowing users to skip some implementation details and build their first end-to-end deep learning model faster. However, ignoring these details limits the opportunity for users to explore the inner workings of each computing module in the deep learning process. Using PyTorch provides more opportunities to think more deeply about deep learning concepts such as back propagation and other training processes.
In other words, Keras is much simpler than PyTorch, but it is not a "toy". It is a serious deep learning tool used by beginners and experienced data scientists.
For example, in the DSTL satellite image feature detection Kaggle competition, the best three teams used Keras for their solutions, and the fourth (deepsense.ai team) used PyTorch and Keras.
It is worth considering whether your deep learning application requires more flexibility than Keras can provide. Depending on your needs, following Rule of least power,Keras may be the perfect solution.
3. Conclusion
Keras: a more concise, simpler API
PyTorch: more flexible, encouraging users to understand the concept of deep learning more deeply
IV. Keras vs PyTorch: popularity and access to learning resources
Framework popularity not only represents ease of use, but community support is also important-tutorials, code bases, and discussion groups. As of June 2018, the popularity of Keras and PyTorch has been growing, whether it's GitHub or arXiv papers (note that most papers that mention Keras also mention its TensorFlow back end). According to KDnuggets, Keras and PyTorch are the fastest growing data science tools.
Although both frameworks are well documented, PyTorch's community support is stronger: its discussion boards are worth visiting for answers you won't find in the documentation or StackOverflow.
We find that Keras-based deep learning courses for beginners are simpler than PyTorch-based courses, which makes the former more popular with beginners. Keras's code readability and unparalleled ease of use make it widely used by deep learning enthusiasts, teachers and powerful Kaggle champions.
For examples of great Keras resources and deep learning courses, see Piotr Migda? The article "Starting deep learning hands-on: image classification on CIFAR-10" and the book "Deep Learning with Python" written by Fran?ois Chollet, the founder of Keras. As for PyTorch resources, we recommend official tutorials that provide a slightly more challenging comprehensive way to learn the inner workings of neural networks.
Conclusion
Keras: plenty of tutorials and reusable code are available
PyTorch: excellent community support and active development
5. Keras vs PyTorch:debug and introspection
Keras encapsulates a large number of computing modules, which makes it difficult to determine the code that is causing the problem.
PyTorch is more detailed than it is, and we can execute the script line by line. Like debug NumPy, we can easily access all the objects in the code and use the print statement (or any standard Python debug statement) to see the problematic code.
Standard networks created by Keras users are an order of magnitude less likely to go wrong than those created by PyTorch users. But if something goes wrong, the damage is huge, and it is often difficult to locate the wrong line of code. PyTorch provides a more straightforward debug experience without paying attention to model complexity. In addition, when you wonder what went wrong, you can look for PyTorch repo to see the readable code.
Conclusion
PyTorch:debug is more capable.
The (potential) frequency of the demand for Keras:debug simple networks is lower
VI. Keras vs PyTorch: export models and cross-platform portability
What are the options for exporting and deploying your own training models in a production environment?
PyTorch saves the model in Pickles, Pickles is based on Python and is not portable, while Keras takes advantage of the more secure approach of JSON + H5 file format (although it is often more difficult to save custom layers in Keras). On the other hand, Keras also has an R language interface, and if the team of data analysts you work with uses R, you will need it.
Keras runs on TensorFlow, which means it has more options to deploy to mobile platforms through TensorFlow for Mobile and TensorFlow Lite. Web applications you write can also be deployed to web pages through TensorFlow.js or Keras.js. For example, you can take a look at this deep learning-driven browser plug-in that detects the trigger of dense phobia: https://github.com/cytadela8/trypophobia.
The process of deriving the PyTorch model is more laborious because of the limitation of its Python code. At present, the widely used method is to use ONNX to transform the PyTorch model into Caffe2 form.
Conclusion
Keras wins: it has more deployment options (directly through the TensorFlow backend) and easier model export.
7. Keras vs PyTorch: performance section
Donald Knuth has a famous saying: immature optimization is the root of all evil (at least most) in programming.
In most cases, speed differences in benchmarking should not be the main criteria for framework selection-especially during the learning phase. GPU time is obviously much cheaper than its data scientist's time. Moreover, in the learning process, performance bottlenecks are mostly caused by failed implementation, unoptimized network and data loading, rather than the running speed of the framework itself. Of course, in order to make a complete comparison, we still have to introduce this aspect. Here we recommend two performance comparison results:
"TensorFlow, Keras and PyTorch Comparison" by Wojtek Rosi ski: https://wrosinski.github.io/deep-learning-frameworks/
Microsoft's "Comparing Deep Learning Frameworks: A Rosetta Stone Approach": https://github.com/ilkarman/DeepLearningFrameworks/
PyTorch is as fast as TensorFlow and may be faster on cyclic neural networks, whereas Keras is usually slower. As the author of the first article pointed out: in most cases, the computational efficiency advantages of high-performance frameworks (that is, PyTorch and TensorFlow) are inferior to those of rapid development environments and the experimental ease of use provided by Keras.
In terms of training speed, PyTorch is better than Keras
8. Keras vs PyTorch: comparison and summary
Both Keras and PyTorch are great choices for beginners in deep learning frameworks. If you are a mathematician, researcher, or want to understand the nature of the model, consider choosing PyTorch. PyTorch is really great when we need more advanced customization and debug (such as using YOLOv3 for target detection or LSTM with attention), or when we need to optimize array expressions instead of neural networks (such as matrix factorization or word2vec algorithms).
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.