+ Post New Thread
Page 2 of 2 FirstFirst 1 2
Results 21 to 24 of 24
  1. #21
    Advanced Member level 5
    Points: 38,675, Level: 48
    Achievements:
    7 years registered

    Join Date
    Jun 2010
    Posts
    6,983
    Helped
    2063 / 2063
    Points
    38,675
    Level
    48

    Re: Tool for transforming python code to FPGA for Machine Learning

    Quote Originally Posted by adwnis123 View Post
    Is it possible to build a CNN on Matlab and transform it to vhdl code? Has anyone experience on this? Thanks...
    Generating VHDL code from matlab requires the paid for HDL coder feature.


    1 members found this post helpful.

    •   AltAdvertisement

        
       

  2. #22
    Full Member level 4
    Points: 1,999, Level: 10

    Join Date
    Jun 2014
    Posts
    209
    Helped
    0 / 0
    Points
    1,999
    Level
    10

    Re: Tool for transforming python code to FPGA for Machine Learning

    Maybe I can get help and use academic credentials, but does it work this way?
    Last edited by adwnis123; 14th April 2020 at 00:08.



    •   AltAdvertisement

        
       

  3. #23
    Advanced Member level 5
    Points: 38,675, Level: 48
    Achievements:
    7 years registered

    Join Date
    Jun 2010
    Posts
    6,983
    Helped
    2063 / 2063
    Points
    38,675
    Level
    48

    Re: Tool for transforming python code to FPGA for Machine Learning

    I am sorry I dont know - I have only used it in a commercial setting.


    1 members found this post helpful.

    •   AltAdvertisement

        
       

  4. #24
    Full Member level 4
    Points: 1,999, Level: 10

    Join Date
    Jun 2014
    Posts
    209
    Helped
    0 / 0
    Points
    1,999
    Level
    10

    Re: Tool for transforming python code to FPGA for Machine Learning

    What should I change in this code:

    Code:
    # baseline model with data augmentation on the cifar10 dataset
    import sys
    from matplotlib import pyplot
    from keras.datasets import cifar10
    from keras.utils import to_categorical
    from keras.models import Sequential
    from keras.layers import Conv2D
    from keras.layers import MaxPooling2D
    from keras.layers import Dense
    from keras.layers import Flatten
    from keras.optimizers import SGD
    from keras.preprocessing.image import ImageDataGenerator
     
    # load train and test dataset
    def load_dataset():
    	# load dataset
    	(trainX, trainY), (testX, testY) = cifar10.load_data()
    	# one hot encode target values
    	trainY = to_categorical(trainY)
    	testY = to_categorical(testY)
    	return trainX, trainY, testX, testY
     
    # scale pixels
    def prep_pixels(train, test):
    	# convert from integers to floats
    	train_norm = train.astype('float32')
    	test_norm = test.astype('float32')
    	# normalize to range 0-1
    	train_norm = train_norm / 255.0
    	test_norm = test_norm / 255.0
    	# return normalized images
    	return train_norm, test_norm
     
    # define cnn model
    def define_model():
    	model = Sequential()
    	model.add(Conv2D(32, (3, 3), activation='relu', kernel_initializer='he_uniform', padding='same', input_shape=(32, 32, 3)))
    	model.add(Conv2D(32, (3, 3), activation='relu', kernel_initializer='he_uniform', padding='same'))
    	model.add(MaxPooling2D((2, 2)))
    	model.add(Conv2D(64, (3, 3), activation='relu', kernel_initializer='he_uniform', padding='same'))
    	model.add(Conv2D(64, (3, 3), activation='relu', kernel_initializer='he_uniform', padding='same'))
    	model.add(MaxPooling2D((2, 2)))
    	model.add(Conv2D(128, (3, 3), activation='relu', kernel_initializer='he_uniform', padding='same'))
    	model.add(Conv2D(128, (3, 3), activation='relu', kernel_initializer='he_uniform', padding='same'))
    	model.add(MaxPooling2D((2, 2)))
    	model.add(Flatten())
    	model.add(Dense(128, activation='relu', kernel_initializer='he_uniform'))
    	model.add(Dense(10, activation='softmax'))
    	# compile model
    	opt = SGD(lr=0.001, momentum=0.9)
    	model.compile(optimizer=opt, loss='categorical_crossentropy', metrics=['accuracy'])
    	return model
     
    # plot diagnostic learning curves
    def summarize_diagnostics(history):
    	# plot loss
    	pyplot.subplot(211)
    	pyplot.title('Cross Entropy Loss')
    	pyplot.plot(history.history['loss'], color='blue', label='train')
    	pyplot.plot(history.history['val_loss'], color='orange', label='test')
    	# plot accuracy
    	pyplot.subplot(212)
    	pyplot.title('Classification Accuracy')
    	pyplot.plot(history.history['accuracy'], color='blue', label='train')
    	pyplot.plot(history.history['val_accuracy'], color='orange', label='test')
    	# save plot to file
    	filename = sys.argv[0].split('/')[-1]
    	pyplot.savefig(filename + '_plot.png')
    	pyplot.close()
     
    # run the test harness for evaluating a model
    def run_test_harness():
    	# load dataset
    	trainX, trainY, testX, testY = load_dataset()
    	# prepare pixel data
    	trainX, testX = prep_pixels(trainX, testX)
    	# define model
    	model = define_model()
    	# create data generator
    	datagen = ImageDataGenerator(width_shift_range=0.1, height_shift_range=0.1, horizontal_flip=True)
    	# prepare iterator
    	it_train = datagen.flow(trainX, trainY, batch_size=64)
    	# fit model
    	steps = int(trainX.shape[0] / 64)
    	history = model.fit_generator(it_train, steps_per_epoch=steps, epochs=100, validation_data=(testX, testY), verbose=0)
    	# evaluate model
    	_, acc = model.evaluate(testX, testY, verbose=0)
    	print('> %.3f' % (acc * 100.0))
    	# learning curves
    	summarize_diagnostics(history)
     
    # entry point, run the test harness
    run_test_harness()
    taken from here:

    https://machinelearningmastery.com/h...lassification/

    in order to accelarate it on PYNQ-Z1??



--[[ ]]--