Hi am am trying to make a stock predicting CNN because I wanted to challenge my self and I cam across this error It thinks that Convd2D is not fully defined but I don't know what else to put there to fix that error. can someone help me here is my code
import tflearn
import numpy as np
from tflearn.layers.conv import conv_2d, max_pool_2d
from tflearn.layers.core import input_data, dropout, fully_connected
from tflearn.layers.estimator import regression
import csv
import math
prices = []
templist = []
X = []
Y = []
i=0
def get_data(filename):
with open(filename, 'r') as csvfile:
csvFileReader = csv.reader(csvfile)
next(csvFileReader)
for row in csvFileReader:
prices.append(float(row[1]))
return
get_data('intc.csv')
i=len(prices)-5
while i>5:
X.append(prices[i-5:i])
Y.append(prices[i-6])
i-=1
#X, Y, test_x, test_y = mnist.load_data(one_hot=True)
X = np.reshape(X,(-1,len(X),len(X[0]),1))
convnet = input_data(shape=[None, 241, 5, None], name='input')
convnet = conv_2d(convnet, 32, 1, activation='relu')
convnet = max_pool_2d(convnet, 1)
convnet = conv_2d(convnet, 64, 1, activation='relu')
convnet = max_pool_2d(convnet, 1)
convnet = fully_connected(convnet, 1024, activation='relu')
convnet = dropout(convnet, 0.8)
convnet = fully_connected(convnet, 1, activation='softmax')
convnet = regression(convnet, optimizer='adam', learning_rate=0.01, loss='categorical_crossentropy', name='targets')
model = tflearn.DNN(convnet)
model.fit({'input': X}, {'targets': Y}, n_epoch=2, snapshot_step=500, show_metric=True)
model.save('quicktest.model')
The error that I get is
File "C:\Users\User\Desktop\Python Projects\Intel_Stock_Price_Prediction.py", line 38, in <module>
convnet = conv_2d(convnet, 32, 1, activation='relu')
File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\tflearn\layers\conv.py", line 85, in conv_2d
restore=restore)
File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\contrib\framework\python\ops\arg_scope.py", line 181, in func_with_args
return func(*args, **current_args)
File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\tflearn\variables.py", line 65, in variable
validate_shape=validate_shape)
File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 1065, in get_variable
use_resource=use_resource, custom_getter=custom_getter)
File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 962, in get_variable
use_resource=use_resource, custom_getter=custom_getter)
File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 367, in get_variable
validate_shape=validate_shape, use_resource=use_resource)
File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 352, in _true_getter
use_resource=use_resource)
File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 685, in _get_single_variable
"but instead was %s." % (name, shape))
ValueError: Shape of a new variable (Conv2D/W) must be fully defined, but instead was (1, 1, ?, 32).
Can someone help please Thanks.
Here the errors is related to the input_data
function. You should fully define input data shape. you can use None
for batch dimension, but not for any other input dimensions.
# replace this line
convnet = input_data(shape=[None, 241, 5, None], name='input')
# hopefully with your correct input dimension. you need provide a value
# in your case
num_channels =1
convnet = input_data(shape=[None, 241, 5, num_channels], name='input')