yolo code
yolo code
Heyang Huang
Stanford University
726 Serra Street, CA, 94305
[email protected]
Abstract
My proposed pipeline can effectively augment enough I further work on their approach. The weakness of their
number of stock prices in the form as time series thanks to method is mentioned in Xiang [5]:
the RGB-GAF transformation module which will be later
discussed in methodology section. We will then have “Let us take a normalized time series X and use the GAF
enough labeled samples to train a YOLO-LITE model to method to imagine it. Despite the presence of both sine
directly locate and classify candlestick patterns on chart and cosine functions in the initial work, now themajority
pictures. The ability to classify directly on chart photo of examples I reviewed use only the cosine function to get
rather than numeric time series form is very important. It the GAF image. Note that for any θ in [0,2𝜋), we have
mimics how real traders think and grant more adaptability also (2𝜋-θ) in [0,2𝜋). Recall that the cosine function in
to classify candlestick charts in various timeframes [0,2𝜋) is symmetric with respect to θ=2𝜋 so that cos(θ)
without major change of code structure. To summarize, equals cos(2𝜋-θ). Back to the GAF matrix, we see that
my proposed pipeline tackles the following three biggest cos(2𝜋-θi-θj)=cos(θi+θj) and therefore 𝜋-θi and 𝜋-θj give
problems in deep learning-based candlestick detection: us the same value as the i-j element of the GAF matrix.
For all θ in [0,𝜋), we know that 𝜋-θ=arccos(-x) and we
1. Not enough training samples available can therefore get the fact that the time series X can give
2. Needs for manual labeling us the same matrix. To resume, if we reverse the sign of
3. Based on numerical values rather than picture, so every point on a time series, the transformation of GAF
require complete rework when the timeframe or results in the same image.”
price range changes.
My solution to this issue is simple: I stack the sine and
2. Related Work cosine GAF as well as GAD graph together and get a
RGB rather than gray scale image. This RGB scales can
show the downward or upward trend with different colors.
2.1. Related work in Gramian Angular Field
Encoding
Given a segment of time series, how do we test whether it 2.2. Related work in fast Object Detection Model
fits into a candlestick pattern? While traditional machine and Pretraining on Abstract photos.
learning and RNN model fails to do a good job, Chen [3]
proposes that we can use Gramian Angular Field to
What object detection model works best for fast object
transform the time series data into 2 dimensional pictures
detection? The financial markets require every detection
and run CNN classifier on it. Chen claims that the CNN
model to be fast, since some of the candlestick algorithms
classifier achieves a n accuracy of 92.5% on simulated
work in min or even second timeframe. As Joseph [6]
data vs 87.2 for traditional machine learning models.
mentioned in YOLO (You Only Look Once), base YOLO
Wang [4] also supports the effectiveness of Gramian
model processes images in real-time at 45 frames per
Angular encoding on time series classification problems:
second. A smaller version of the network, Fast YOLO,
processes an astounding 155 frames per second while still
“We used Tiled Convolutional Neural Networks (tiled
achieving double the mAP of other real-time detectors.
CNNs) on 20 standard datasets to learn high-level features
Compared to state-of-the-art detection systems, YOLO
from the individual and compound GASF-GADF-MTF
makes more localization errors but is less likely to predict
images. Our approaches achieve highly competitive
false positives on background. Finally, YOLO learns very
results when compared to nine of the current best time
general representations of objects. It outperforms other
series classification approaches. Inspired by the bijection
detection methods, including DPM and R-CNN, when
property of GASF on 0/1 rescaled data, we train Denoised
generalizing from natural images to other domains like
artwork. YOLO is both fast in recognition and pre-train.
Moreover, it can achieve good result on non-natural
photos.
3. Methods
The pipeline consists of four modules: GAF pattern
classification, ARIMA data augmentation, auto-labeling,
and Yolo model training, as shown below in figure 3. The
GAF pattern classifier module first converts candlesticks
into an enhanced version of Gramian Angular Field, then
trains a simple CNN classifier on the Granmian Angular
field images. The ARIMA data augmentation module then
fits an ARIMA model on original time series and Figure 4: Vanilla Gramian Angular Field Conversion
extrapolates the time series many times longer, given the
length of original sequence. Then, the auto-labeling Following the step above, I reproduce the following
module uses a moving window to classify whether a GASF representation as mentioned by Chen [3] below in
segment of the extrapolated time series forms a certain Figure 5 and 6. If we compare them, we can find the
candlestick pattern. In this way, the module augments the angular field representation does capture the fundamental
training set many times of its original size. Last, the Yolo difference in the two patterns and show it in the form of
module fits a Yolo-Lite module on the augmented dataset. color gradient shifts.
Figure 9: ARIMA
5.2. Hyperparameters
After k-fold validation (k=10), the best setup of
hyperparameter for YOLO is listed below: Figure: validation loss for YOLO-LITE
I fail to find a solid explanation for these errors, since 5. TD_Ameritrade for candlestick charts picture
there are barely any samples in training set that consist of
only one bar. I guess it may be due to the background
8. References imperative-style-high-performance-deep-learning-
library.pdf.
[1] Tharavanij, P., Siraprapasiri, V. & Rajchamaha, K.
Performance of technical trading rules: evidence from
Southeast Asian stock markets. SpringerPlus 4, 552 (2015).
https://doi.org/10.1186/s40064-015-1334-7
[2] Morris, Greg L. Candlestick Charting Explained: Timeless
Techniques for Trading stocks and Sutures. McGraw Hill
Professional, 2006. FirstName Alpher and FirstName
Gamow. Can a computer frobnicate? In CVPR, pages 234–
778, 2005.
[3] Chen, Jun-Hao, και Yun-Cheng Tsai. ‘Encoding
Candlesticks as Images for Patterns Classification Using
Convolutional Neural Networks’. arXiv, 2019.
https://doi.org/10.48550/ARXIV.1901.05237.
[4] Wang, Zhiguang, and Tim Oates. "Imaging time-series to
improve classification and imputation." In Twenty-Fourth
International Joint Conference on Artificial Intelligence.
2015.
[5] Xiang, RGB GAF image: A possible solution to one weak
point of Gramian Angular Field Imaging, 2022