Skip to content

Instantly share code, notes, and snippets.

💭
Active!

Vivek Maskara maskaravivek

💭
Active!
View GitHub Profile
View My_Custom_Generator.py
from tensorflow import keras
class My_Custom_Generator(keras.utils.Sequence):
def __init__(self, images, labels, batch_size):
self.images = images
self.labels = labels
self.batch_size = batch_size
View dataset_batches.py
train, test = datasets['train'], datasets['validation']
train_batch = train.map(
lambda image, label: (tf.image.resize(image, (448, 448)), label)).shuffle(100).batch(batch_size).repeat()
validation_batch = test.map(
lambda image, label: (tf.image.resize(image, (448, 448)), label)
).shuffle(100).batch(batch_size).repeat()
View dataset_size.py
train_examples = imagenette_info.splits['train'].num_examples
validation_examples = imagenette_info.splits['validation'].num_examples
View load_dataset.py
import tensorflow_datasets as tfds
imagenette_builder = tfds.builder("imagenette/full-size")
imagenette_info = imagenette_builder.info
imagenette_builder.download_and_prepare()
datasets = imagenette.as_dataset(as_supervised=True)
View UserDao.kt
@Query("SELECT * FROM user")
fun fetchUsers(): DataSource.Factory<Int, User>
View initRecyclerView.kt
private fun initRecyclerView() {
val layoutManager = LinearLayoutManager(this)
userRecyclerView.setLayoutManager(layoutManager)
userList!!.observe(this, Observer { pagedList ->
adapter.submitList(pagedList)
})
userRecyclerView.setAdapter(adapter)
}
View setup_paged_list.kt
private var userBoundaryCallback: UserBoundaryCallback? = null
var userList: LiveData<PagedList<User>>? = null
fun setup() {
appDatabase = initDb()
userBoundaryCallback = UserBoundaryCallback(
appDatabase!!.userDao()
)
val pagedListConfig = PagedList.Config.Builder()
View UserListAdapter.kt
class UserListAdapter internal constructor() :
PagedListAdapter<User, UserViewHolder>(DIFF_CALLBACK) {
/**
* Initializes the view holder with contribution data
*/
override fun onBindViewHolder(holder: UserViewHolder, position: Int) {
holder.bind(getItem(position))
}
/**
View UserViewHolder.kt
class UserViewHolder(inflater: LayoutInflater, parent: ViewGroup) :
RecyclerView.ViewHolder(inflater.inflate(R.layout.layout_user, parent, false)) {
private var tvUser: TextView? = null
init {
tvUser = itemView.findViewById(R.id.name_tv)
}
fun bind(user: User?) {
View UserBoundaryCallback.kt
class UserBoundaryCallback constructor(val userDao: UserDao?) :
PagedList.BoundaryCallback<User?>() {
private val compositeDisposable: CompositeDisposable = CompositeDisposable()
override fun onZeroItemsLoaded() {
fetchUsers()
}
override fun onItemAtFrontLoaded(itemAtFront: User) {
fetchUsers()
You can’t perform that action at this time.